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

Revision:
17:94c385ff2641
Parent:
15:a627638edd9c
Child:
18:be0130c42925
diff -r cfb774e3e7fc -r 94c385ff2641 tsk_dist.cpp
--- a/tsk_dist.cpp	Wed Dec 16 22:37:56 2015 +0000
+++ b/tsk_dist.cpp	Fri Dec 18 15:23:21 2015 +0000
@@ -1,16 +1,26 @@
 #include "mbed.h"
 #include "rtos.h"
 
+#include "tsk_main.h"
 #include "tsk_dist.h"
 
 
-struct dist_data_struct dist_data = { 10000, 10.0f };
-
+struct dist_data_struct dist_data;
 
 static DigitalOut  trigDist(PB_9);
 static InterruptIn echoDist(PA_6);
 
-static Timer   timer;
+static Timer timer;
+
+uint32_t initDist(void const *args) {
+    
+    dist_data.distance = 0.0f;
+    dist_data.timerTicks = 0;
+
+    trigDist = 0;
+    
+    return 1;
+}
 
 static void rising(void) {
     timer.start();
@@ -21,10 +31,12 @@
     echoDist.rise(0);
     echoDist.fall(0);
 
+//    mutexDist.lock();
     dist_data.timerTicks = timer.read_us();
         
     // 340 ms-1
     dist_data.distance = (timer.read()/2.0f - 0.0f)*340.0f*1000.0f;
+//    mutexDist.unlock();
 
     // Vynuluj timer
     timer.reset();
@@ -39,8 +51,10 @@
         trigDist = 0;
     
         if (echoDist != 0) {
+            mutexDist.lock();
             dist_data.timerTicks = 0;
             dist_data.distance = 0.0f;
+            mutexDist.unlock();
         } else {
             // Vynuluj timer
             timer.stop();
@@ -51,6 +65,6 @@
             echoDist.fall(&falling);
         }
         
-        Thread::wait(500);
+        Thread::wait(1000);
     }
 }