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

Committer:
dzoni
Date:
Mon Dec 14 11:32:15 2015 +0000
Revision:
9:645f0e517017
Child:
13:f62b10a6e1c5
Tasks split into separate source files. Compile OK. For testing.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dzoni 9:645f0e517017 1 #include "mbed.h"
dzoni 9:645f0e517017 2 #include "rtos.h"
dzoni 9:645f0e517017 3
dzoni 9:645f0e517017 4 #include "tsk_dist.h"
dzoni 9:645f0e517017 5
dzoni 9:645f0e517017 6
dzoni 9:645f0e517017 7 struct dist_data_struct dist_data = { 10000, 10.0f };
dzoni 9:645f0e517017 8
dzoni 9:645f0e517017 9
dzoni 9:645f0e517017 10 static DigitalOut trigDist(PB_9);
dzoni 9:645f0e517017 11 static DigitalIn echoDist(PA_6);
dzoni 9:645f0e517017 12
dzoni 9:645f0e517017 13 static Timer timer;
dzoni 9:645f0e517017 14
dzoni 9:645f0e517017 15
dzoni 9:645f0e517017 16 void dist_thread(void const *args) {
dzoni 9:645f0e517017 17
dzoni 9:645f0e517017 18 while (true) {
dzoni 9:645f0e517017 19 // Dej puls na trig
dzoni 9:645f0e517017 20 trigDist = 1;
dzoni 9:645f0e517017 21 Thread::wait(1);
dzoni 9:645f0e517017 22 trigDist = 0;
dzoni 9:645f0e517017 23
dzoni 9:645f0e517017 24 if (echoDist != 0) {
dzoni 9:645f0e517017 25 dist_data.timerTicks = 0;
dzoni 9:645f0e517017 26 dist_data.distance = 0.0f;
dzoni 9:645f0e517017 27 } else {
dzoni 9:645f0e517017 28 timer.stop();
dzoni 9:645f0e517017 29 timer.reset();
dzoni 9:645f0e517017 30
dzoni 9:645f0e517017 31 // Cekej na hranu na Echo
dzoni 9:645f0e517017 32 while (echoDist != 1)
dzoni 9:645f0e517017 33 ;
dzoni 9:645f0e517017 34
dzoni 9:645f0e517017 35 // Zacni merit cas
dzoni 9:645f0e517017 36 timer.start();
dzoni 9:645f0e517017 37
dzoni 9:645f0e517017 38 // Cekej na hranu na Echo
dzoni 9:645f0e517017 39 while (echoDist != 0)
dzoni 9:645f0e517017 40 ;
dzoni 9:645f0e517017 41
dzoni 9:645f0e517017 42 // Zastav mereni
dzoni 9:645f0e517017 43 timer.stop();
dzoni 9:645f0e517017 44
dzoni 9:645f0e517017 45 dist_data.timerTicks = timer.read_us();
dzoni 9:645f0e517017 46
dzoni 9:645f0e517017 47 // 340 ms-1
dzoni 9:645f0e517017 48 dist_data.distance = (timer.read()/2.0f - 0.0f)*340.0f*1000.0f;
dzoni 9:645f0e517017 49 }
dzoni 9:645f0e517017 50
dzoni 9:645f0e517017 51 Thread::wait(500);
dzoni 9:645f0e517017 52 }
dzoni 9:645f0e517017 53 }