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
main.cpp
- Committer:
- mmarine3
- Date:
- 2020-04-22
- Revision:
- 9:f4f03767acc0
- Parent:
- 8:c0a6a3363e43
- Child:
- 10:7a939a54515e
File content as of revision 9:f4f03767acc0:
#include "mbed.h" #include "rtos.h" #include "SDFileSystem.h" #include "uLCD_4DGL.h" #include "XNucleo53L0A1.h" #include "ultrasonic.h" #include "wave_player.h" //#include <stdio.h> #include <string> //I2C sensor pins #define VL53L0_I2C_SDA p28 #define VL53L0_I2C_SCL p27 uLCD_4DGL uLCD(p13, p14, p12); // Initialize uLCD serial tx, serial rx, reset pin; SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card RawSerial BT(p9,p10); //Initialize Blutooth //Serial BT(p9,p10); AnalogOut speaker(p18); //Initialize speaker wave_player waver(&speaker); //Initialize Waveplayer Mutex mutex; Mutex dist; DigitalOut MyLED(LED1); int sdist = 0; void sonar(int distance) { //put code here to execute when the sonar distance has changed dist.lock(); sdist = distance; dist.unlock(); //printf("Sonar Distance:\r\n %d", sdist); } 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 sonar when the distance changes void Sonar(void const* arguments) { mu.startUpdates();//start measuring the distance while(1) { //Do something else here mu.checkDistance(); //call checkDistance() as much as possible, as this is where //the class checks if dist needs to be called. Thread::wait(10); } } //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("Sonar Distance:\n %d", sdist); dist.unlock(); Thread::wait(1000); //Allow time to read value before reprint } } int main() { uLCD.cls(); uLCD.baudrate(BAUD_3000000); //wait(1.0); //blu.attach(&parse_message,Serial::RxIrq); //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(Sonar);//Initialize Sonar thread //mu.startUpdates(); /* //Code to read and play a file FILE *wave_file; //printf("Hello World"); Thread::wait(1000); wave_file=fopen("/sd/test.wav","r"); //serial_mutex.lock(); if(wave_file==NULL) printf("file open error!\n\n\r"); //serial_mutex.unlock(); waver.play(wave_file); fclose(wave_file); */ //Loop to validate the main loop is executing while(1) { //mu.checkDistance(); //MyLED = !MyLED; //Thread::wait(100); } }