Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed mbed-rtos 4DGL-uLCD-SE HC_SR04_Ultrasonic_Library
Diff: main.cpp
- Revision:
- 8:c0a6a3363e43
- Parent:
- 7:85d42006e380
- Child:
- 9:f4f03767acc0
--- a/main.cpp Wed Apr 22 17:30:31 2020 +0000 +++ b/main.cpp Wed Apr 22 18:37:33 2020 +0000 @@ -4,6 +4,7 @@ #include "uLCD_4DGL.h" #include "XNucleo53L0A1.h" #include "ultrasonic.h" +#include "wave_player.h" //#include <stdio.h> #include <string> @@ -20,21 +21,22 @@ AnalogOut speaker(p18); //NEW wave_player waver(&speaker);//NEW Mutex mutex; +Mutex dist; DigitalOut MyLED(LED1); //needed for TOF static XNucleo53L0A1 *board=NULL; -void dist(int distance) +/*void sonar(int distance) { //put code here to execute when the sonar distance has changed -} +}*/ -ultrasonic mu(p30, p29, .1, 1, &dist); //Set the trigger pin to p30 and the echo pin to p29 +//ultrasonic mu(p30, p29, .1, 1, &sonar); //Set the trigger pin to p30 and the echo pin to p29 //have updates every .1 seconds and a timeout after 1 //second, and call dist when the distance changes - +uint32_t far; //Global variable to hold lidar TOF distance void TOF(void const *arguments) { //initialize the TOF int status; @@ -53,11 +55,18 @@ status = board->init_board(); } - /* + + - How to get distance value - status = board->sensor_centre->get_distance(&distance); - + //Loop that reads in the TOF value 100 times per second + while(1){ + status = board->sensor_centre->get_distance(&distance); //How to get distance value + dist.lock(); + far = distance; + dist.unlock(); + Thread::wait(10); + } + /* How you would print TOF to pc serial if (status == VL53L0X_ERROR_NONE) { pc.printf("D=%ld mm\r\n", distance); @@ -66,18 +75,33 @@ */ } +//Thread to print the TOF and Sonar Values to the LCD +void LCD(void const *arguments) +{ + Thread::wait(1000); //Wait for lidar and sonar setup + while(1) + { + uLCD.cls(); + dist.lock(); + uLCD.printf("TOF Distance %i \n", far); + dist.unlock(); + Thread::wait(1000); //Allow time to read value before reprint + } +} + int main() { - //NEW uLCD.cls(); uLCD.baudrate(BAUD_3000000); //wait(1.0); //blu.attach(&parse_message,Serial::RxIrq); - //Was used to interupt if reading in a blutooth command + //Was used in lab 3 to interupt if reading in a blutooth command //Thread t#(name_of_thread_function); + Thread t1(LCD);//Initialize LCD thread + Thread t2(TOF);//Initialize TOF thread - + /* //Code to read and play a file FILE *wave_file; //printf("Hello World"); Thread::wait(1000); @@ -87,4 +111,12 @@ //serial_mutex.unlock(); waver.play(wave_file); fclose(wave_file); + */ + + //Loop to validate the main loop is executing + while(1) + { + MyLED = !MyLED; + Thread::wait(100); + } } \ No newline at end of file