Our Programm to build up from the PES Board Example
Dependencies: PM2_Libary
Diff: main.cpp
- Revision:
- 15:a2c188ed294f
- Parent:
- 14:db46f47b0480
- Child:
- 16:2de2a437afdc
--- a/main.cpp Tue Apr 06 12:20:31 2021 +0000 +++ b/main.cpp Thu Feb 10 12:13:50 2022 +0000 @@ -1,9 +1,6 @@ #include "mbed.h" -#include "platform/mbed_thread.h" -using namespace std::chrono; - -InterruptIn user_button(USER_BUTTON); +InterruptIn user_button(PC_13); DigitalOut led(LED1); bool executeMainTask = false; @@ -15,8 +12,8 @@ void button_rise(); /* create analog input object */ -AnalogIn analogIn(PA_0); -float dist = 0.0f; +AnalogIn analogIn(PC_2); +float dist_IRSensor = 0.0f; int main() { @@ -33,10 +30,10 @@ if (executeMainTask) { /* read analog input */ - dist = analogIn.read()*3.3f; + dist_IRSensor = analogIn.read() * 3.3f; /* do only output what's really necessary, outputting "Measured value in mV: "" within the loop is no good solution */ - printf("Measured value in mV: %d\r\n", (static_cast<int>(dist * 1e3))); + printf("Measured value in mV: %d\r\n", (static_cast<int>(dist_IRSensor * 1e3))); /* visual feedback that the main task is executed */ led = !led; @@ -47,7 +44,7 @@ /* ------------- stop hacking ------------- -------------*/ - int T_loop_ms = duration_cast<milliseconds>(loop_timer.elapsed_time()).count(); + int T_loop_ms = std::chrono::duration_cast<std::chrono::milliseconds>(loop_timer.elapsed_time()).count(); int dT_loop_ms = Ts_ms - T_loop_ms; thread_sleep_for(dT_loop_ms); } @@ -61,7 +58,7 @@ void button_rise() { - int t_button_ms = duration_cast<milliseconds>(user_button_timer.elapsed_time()).count(); + int t_button_ms = std::chrono::duration_cast<std::chrono::milliseconds>(user_button_timer.elapsed_time()).count(); user_button_timer.stop(); if (t_button_ms > 200) { executeMainTask = !executeMainTask;