![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Simple test program to get familiar with functionality of MBED RTOS on ST Nucleo-F411RE. Tasks for LED blinking, user button, temperature measurement with DS1620, temperature measurement with internal temperature sensor of ST32F411RE, ultrasonic distance measurement and displaying result on 16x2 TextLCD.
Dependencies: DS1620_improved TextLCD_improved mbed-rtos mbed
Diff: tsk_dist.cpp
- Revision:
- 15:a627638edd9c
- Parent:
- 13:f62b10a6e1c5
- Child:
- 17:94c385ff2641
--- a/tsk_dist.cpp Mon Dec 14 19:48:36 2015 +0000 +++ b/tsk_dist.cpp Mon Dec 14 21:46:45 2015 +0000 @@ -8,10 +8,27 @@ static DigitalOut trigDist(PB_9); -static DigitalIn echoDist(PA_6); +static InterruptIn echoDist(PA_6); static Timer timer; +static void rising(void) { + timer.start(); +} + +static void falling(void) { + timer.stop(); + echoDist.rise(0); + echoDist.fall(0); + + dist_data.timerTicks = timer.read_us(); + + // 340 ms-1 + dist_data.distance = (timer.read()/2.0f - 0.0f)*340.0f*1000.0f; + + // Vynuluj timer + timer.reset(); +} void dist_thread(void const *args) { @@ -25,29 +42,15 @@ dist_data.timerTicks = 0; dist_data.distance = 0.0f; } else { + // Vynuluj timer timer.stop(); timer.reset(); - // Cekej na hranu na Echo - while (echoDist != 1) - ; - - // Zacni merit cas - timer.start(); - - // Cekej na hranu na Echo - while (echoDist != 0) - ; - - // Zastav mereni - timer.stop(); - - dist_data.timerTicks = timer.read_us(); - - // 340 ms-1 - dist_data.distance = (timer.read()/2.0f - 0.0f)*340.0f*1000.0f; + // Cekej na hrany na Echo + echoDist.rise(&rising); + echoDist.fall(&falling); } - Thread::wait(1000); + Thread::wait(500); } }