Severin Kiefer
/
PM2_Example_IRSensor
Workshop 1
main.cpp
- Committer:
- pmic
- Date:
- 2021-03-12
- Revision:
- 1:4e0e4d0363d9
- Parent:
- 0:5d4d21d56334
- Child:
- 2:4ba1937ce284
File content as of revision 1:4e0e4d0363d9:
#include "mbed.h" #include "platform/mbed_thread.h" #define pi 3.14159265358979323846 InterruptIn user_button(USER_BUTTON); DigitalOut led(LED1); Serial pc(SERIAL_TX, SERIAL_RX); bool executeMainTask = false; Timer user_button_timer, loop_timer; int Ts_ms = 50; void button_fall(); void button_rise(); AnalogIn analogIn(PA_0); float dist = 0.0f; int main() { pc.baud(115200); user_button.fall(&button_fall); user_button.rise(&button_rise); loop_timer.reset(); while (true) { /* ------------- start hacking ------------- -------------*/ if(executeMainTask) { dist = analogIn.read()*3.3f; printf("measurement: %9.6f\r\n", dist); } else { } /* ------------- stop hacking ------------- -------------*/ if(executeMainTask) { led = !led; } int dT_loop = Ts_ms - loop_timer.read_ms(); thread_sleep_for(dT_loop); } } void button_fall() { user_button_timer.reset(); user_button_timer.start(); } void button_rise() { int t_button = user_button_timer.read_ms(); user_button_timer.stop(); if(t_button > 200) executeMainTask = !executeMainTask; }