Samuel Rusterholz
/
PM2_Example_IRSensor
Workshop 1
Diff: main.cpp
- Revision:
- 3:aa1d854807fe
- Parent:
- 2:4ba1937ce284
- Child:
- 4:dcdcb25d1069
--- a/main.cpp Fri Mar 12 23:26:17 2021 +0100 +++ b/main.cpp Sat Mar 13 12:09:11 2021 +0000 @@ -3,9 +3,11 @@ #define pi 3.14159265358979323846 +using namespace std::chrono; + InterruptIn user_button(USER_BUTTON); DigitalOut led(LED1); -Serial pc(SERIAL_TX, SERIAL_RX); +// Serial pc(SERIAL_TX, SERIAL_RX); bool executeMainTask = false; Timer user_button_timer, loop_timer; @@ -19,7 +21,7 @@ int main() { - pc.baud(115200); + // pc.baud(115200); user_button.fall(&button_fall); user_button.rise(&button_rise); loop_timer.reset(); @@ -30,7 +32,7 @@ if(executeMainTask) { dist = analogIn.read()*3.3f; - printf("measurement: %9.6f\r\n", dist); + // printf("measurement: %9.6f\r\n", dist); } else { } @@ -40,7 +42,7 @@ if(executeMainTask) { led = !led; } - int dT_loop = Ts_ms - loop_timer.read_ms(); + int dT_loop = Ts_ms - duration_cast<milliseconds>(loop_timer.elapsed_time()).count(); thread_sleep_for(dT_loop); } } @@ -53,7 +55,7 @@ void button_rise() { - int t_button = user_button_timer.read_ms(); + int t_button = duration_cast<milliseconds>(user_button_timer.elapsed_time()).count(); user_button_timer.stop(); if(t_button > 200) executeMainTask = !executeMainTask; } \ No newline at end of file