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 21:46:45 2015 +0000
Revision:
15:a627638edd9c
Parent:
13:f62b10a6e1c5
Child:
17:94c385ff2641
Hangs out in display ("Raw: 20" and that's all)

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 15:a627638edd9c 11 static InterruptIn echoDist(PA_6);
dzoni 9:645f0e517017 12
dzoni 9:645f0e517017 13 static Timer timer;
dzoni 9:645f0e517017 14
dzoni 15:a627638edd9c 15 static void rising(void) {
dzoni 15:a627638edd9c 16 timer.start();
dzoni 15:a627638edd9c 17 }
dzoni 15:a627638edd9c 18
dzoni 15:a627638edd9c 19 static void falling(void) {
dzoni 15:a627638edd9c 20 timer.stop();
dzoni 15:a627638edd9c 21 echoDist.rise(0);
dzoni 15:a627638edd9c 22 echoDist.fall(0);
dzoni 15:a627638edd9c 23
dzoni 15:a627638edd9c 24 dist_data.timerTicks = timer.read_us();
dzoni 15:a627638edd9c 25
dzoni 15:a627638edd9c 26 // 340 ms-1
dzoni 15:a627638edd9c 27 dist_data.distance = (timer.read()/2.0f - 0.0f)*340.0f*1000.0f;
dzoni 15:a627638edd9c 28
dzoni 15:a627638edd9c 29 // Vynuluj timer
dzoni 15:a627638edd9c 30 timer.reset();
dzoni 15:a627638edd9c 31 }
dzoni 9:645f0e517017 32
dzoni 9:645f0e517017 33 void dist_thread(void const *args) {
dzoni 9:645f0e517017 34
dzoni 9:645f0e517017 35 while (true) {
dzoni 9:645f0e517017 36 // Dej puls na trig
dzoni 9:645f0e517017 37 trigDist = 1;
dzoni 9:645f0e517017 38 Thread::wait(1);
dzoni 9:645f0e517017 39 trigDist = 0;
dzoni 9:645f0e517017 40
dzoni 9:645f0e517017 41 if (echoDist != 0) {
dzoni 9:645f0e517017 42 dist_data.timerTicks = 0;
dzoni 9:645f0e517017 43 dist_data.distance = 0.0f;
dzoni 9:645f0e517017 44 } else {
dzoni 15:a627638edd9c 45 // Vynuluj timer
dzoni 9:645f0e517017 46 timer.stop();
dzoni 9:645f0e517017 47 timer.reset();
dzoni 9:645f0e517017 48
dzoni 15:a627638edd9c 49 // Cekej na hrany na Echo
dzoni 15:a627638edd9c 50 echoDist.rise(&rising);
dzoni 15:a627638edd9c 51 echoDist.fall(&falling);
dzoni 9:645f0e517017 52 }
dzoni 9:645f0e517017 53
dzoni 15:a627638edd9c 54 Thread::wait(500);
dzoni 9:645f0e517017 55 }
dzoni 9:645f0e517017 56 }