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:
- 10:7a939a54515e
- Parent:
- 9:f4f03767acc0
- Child:
- 11:f5d0c8bf1849
diff -r f4f03767acc0 -r 7a939a54515e main.cpp
--- a/main.cpp Wed Apr 22 21:22:28 2020 +0000
+++ b/main.cpp Fri Apr 24 03:00:36 2020 +0000
@@ -2,28 +2,26 @@
#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
+RawSerial blue(p9,p10); //Initialize Blutooth
//Serial BT(p9,p10);
AnalogOut speaker(p18); //Initialize speaker
wave_player waver(&speaker); //Initialize Waveplayer
-Mutex mutex;
+Mutex serial_mutex;
Mutex dist;
DigitalOut MyLED(LED1);
-int sdist = 0;
+volatile int musicChoice = 0;
+//musicChoice can be values 0 to 3
+voltatile int sdist = 0;
void sonar(int distance)
{
//put code here to execute when the sonar distance has changed
@@ -55,15 +53,101 @@
Thread::wait(1000); //Wait for lidar and sonar setup
while(1)
{
+ serial_mutex.lock();
uLCD.cls();
dist.lock();
uLCD.printf("Sonar Distance:\n %d", sdist);
dist.unlock();
+ serial_mutex.unlock();
Thread::wait(1000); //Allow time to read value before reprint
}
}
+void bluetooth(void const *arguments)
+{
+ char bnum=0;
+ char bhit=0;
+ while(1)
+ {
+ serial_mutex.lock();
+ if(!blue.readable()){
+ Thread::yield();
+ } else {
+ if (blue.getc()=='!') {
+ if (blue.getc()=='B') { //button data packet
+ bnum = blue.getc(); //button number
+ bhit = blue.getc(); //1=hit, 0=release
+ if (blue.getc()==char(~('!' + 'B' + bnum + bhit))) { //checksum OK?
+
+ switch (bnum) {
+ case '1': //number button 1
+ if (bhit=='1') {
+ musicChoice = 0;
+ } else {
+ //add release code here
+ }
+ break;
+ case '2': //number button 2
+ if (bhit=='1') {
+ musicChoice = 1;
+ } else {
+ //add release code here
+ }
+ break;
+ case '3': //number button 3
+ if (bhit=='1') {
+ musicChoice = 2;
+ } else {
+ //add release code here
+ }
+ break;
+ case '4': //number button 4
+ if (bhit=='1') {
+ //add hit code here
+ } else {
+ //add release code here
+ }
+ break;
+ case '5': //button 5 up arrow
+ if (bhit=='1') {
+ musicChoice = 3;
+ } else {
+ //add release code here
+ }
+ break;
+ case '6': //button 6 down arrow
+ if (bhit=='1') {
+ //add hit code here
+ } else {
+ //add release code here
+ }
+ break;
+ case '7': //button 7 left arrow
+ if (bhit=='1') {
+ //add hit code here
+ } else {
+ //add release code here
+ }
+ break;
+ case '8': //button 8 right arrow
+ if (bhit=='1') {
+ //add hit code here
+ } else {
+ //add release code here
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ }
+ }
+ serial_mutex.unlock();
+ }
+}
+
int main()
{
uLCD.cls();
@@ -77,7 +161,6 @@
Thread t2(Sonar);//Initialize Sonar thread
- //mu.startUpdates();
/* //Code to read and play a file
FILE *wave_file;
//printf("Hello World");
@@ -93,7 +176,6 @@
//Loop to validate the main loop is executing
while(1)
{
- //mu.checkDistance();
//MyLED = !MyLED;
//Thread::wait(100);
}