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:
- 21:4fef6bf7582c
- Parent:
- 20:1dc516a6a941
- Child:
- 22:8f262e8f65b4
--- a/main.cpp Sun Apr 26 20:28:51 2020 +0000
+++ b/main.cpp Sun Apr 26 21:08:00 2020 +0000
@@ -27,6 +27,8 @@
//musicChoice can be values 0 to 3
volatile int sdist = 0;
volatile int counter = 0;
+volatile int numTowards = 0;
+volatile int numAway = 0;
float note1[2]= {1568.0, 0.0
};
@@ -115,12 +117,26 @@
serial_mutex.lock();
uLCD.cls();
uLCD.baudrate(BAUD_3000000);
+ uLCD.printf("Sonar Dist:\nTowards: \nAway: \nCounter: \nSong: \n");
serial_mutex.unlock();
+ char str1[4];
+
while(1) {
serial_mutex.lock();
- uLCD.cls();
+ //uLCD.cls();
dist.lock();
- uLCD.printf("Sonar Distance:\n %d\n Counter: %d \n Song: %d", sdist, counter, musicChoice);
+ //uLCD.filled_rectangle(90,0,128,40,BLACK);
+ sprintf(str1,"%d ",sdist);
+ uLCD.text_string(str1,12,0,FONT_5X7,GREEN);
+ sprintf(str1,"%d ",numTowards);
+ uLCD.text_string(str1,12,1,FONT_5X7,GREEN);
+ sprintf(str1,"%d ",numAway);
+ uLCD.text_string(str1,12,2,FONT_5X7,GREEN);
+ sprintf(str1,"%d ",counter);
+ uLCD.text_string(str1,12,3,FONT_5X7,GREEN);
+ sprintf(str1,"%d ",musicChoice);
+ uLCD.text_string(str1,12,4,FONT_5X7,GREEN);
+ //uLCD.printf("Sonar Dist:%d\nTowards: %d\nAway: %d\nCounter: %d \nSong: %d\n", sdist,numTowards,numAway, counter, musicChoice);
dist.unlock();
serial_mutex.unlock();
Thread::wait(100); //Allow time to read value before reprint
@@ -230,6 +246,7 @@
break;
case '7': //button 7 left arrow
if (bhit=='1') {
+ volume = .05;
//add hit code here
} else {
//add release code here
@@ -237,6 +254,7 @@
break;
case '8': //button 8 right arrow
if (bhit=='1') {
+ volume = 1;
//add hit code here
} else {
//add release code here
@@ -264,8 +282,6 @@
int main()
{
- //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);
@@ -297,17 +313,20 @@
//NEW CODE
if(movingTowards)
{
- ++counter;
+ ++numTowards;
+ counter++;
state = 1;
- }
- if(movingAway)
+ }else if(movingAway)
{
- --counter;
+ ++numAway;
+ counter++;
state = 1;
+ }else
+ {
+ counter++; //Other case to incriment if neither towards or away
}
//
//right now just adding to main counter
- //counter++;
}
if (state == 1 && allZero){
state = 0;