![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
semi integrated
Dependencies: Speaker mbed 4DGL-uLCD-SE hcsr04
Diff: main.cpp
- Revision:
- 10:f29ed3675509
- Parent:
- 9:d1b00a2a8e25
- Child:
- 11:68194bd43e0b
--- a/main.cpp Wed Dec 16 12:11:32 2020 +0000 +++ b/main.cpp Wed Dec 16 13:18:49 2020 +0000 @@ -1,10 +1,13 @@ #include "mbed.h" #include "hcsr04.h" #include "Speaker.h" +#include "uLCD_4DGL.h" -HCSR04 usensor(p25,p6); +HCSR04 distSens(p25,p6); Serial pc(USBTX, USBRX); Speaker mySpeaker(p18); +uLCD_4DGL uLCD(p9,p10,p11); + unsigned int dist; @@ -14,38 +17,42 @@ int main() { - + uLCD.text_width(1); // Normal size + uLCD.text_height(1); // Normal size + uLCD.locate(10, 13); // Move cursor + uLCD.color(BLUE); // Change text color + uLCD.printf("Reverse"); + uLCD.rectangle(65, 117, 126, 127, 0x0000FF); while(1) { - usensor.start(); - + distSens.start(); averageDistance(); - beeping(); pc.printf("cm:%ld\n",dist ); - wait_ms(50); + uLCD.text_width(1); // Normal size + uLCD.text_height(1); // Normal size + uLCD.locate(10, 15); // Move cursor + uLCD.color(WHITE); // Change text color + uLCD.printf("cm:%1d\n",dist ); + } } float averageDistance() /** Divide the running total by 10 to get the average distance to get more accurate readings on the sensor**/ { - int a = usensor.get_dist_cm(); - int b = usensor.get_dist_cm(); - int c = usensor.get_dist_cm(); - int d = usensor.get_dist_cm(); - int e = usensor.get_dist_cm(); - int f = usensor.get_dist_cm(); - int g = usensor.get_dist_cm(); - int h = usensor.get_dist_cm(); - int i = usensor.get_dist_cm(); - int j = usensor.get_dist_cm(); + int a = distSens.get_dist_cm(); + int b = distSens.get_dist_cm(); + int c = distSens.get_dist_cm(); + int d = distSens.get_dist_cm(); + int e = distSens.get_dist_cm(); + int f = distSens.get_dist_cm(); + int g = distSens.get_dist_cm(); + int h = distSens.get_dist_cm(); + int i = distSens.get_dist_cm(); + int j = distSens.get_dist_cm(); dist = (a+b+c+d+e+f+g+h+i+j)/10; return dist; } void beeping() -/* -@Brief Function to create the effect of varying beeping sounds depending on how close the sensor is to an object interspersed with -the led changing color depending on the distance - */ { int distance = averageDistance(); @@ -62,6 +69,6 @@ if (distance < 20) i=0.15; if (distance < 10) i=0.1; if (distance < 5) i=0.05; - mySpeaker.PlayNote(329.63, i, 1.0); + mySpeaker.PlayNote(600, i, 5.0); } \ No newline at end of file