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: Speaker mbed 4DGL-uLCD-SE hcsr04
Diff: main.cpp
- Revision:
- 12:730a95b81992
- Parent:
- 11:68194bd43e0b
- Child:
- 13:a3cdbad9daf4
diff -r 68194bd43e0b -r 730a95b81992 main.cpp
--- a/main.cpp Wed Dec 16 15:05:27 2020 +0000
+++ b/main.cpp Wed Dec 16 17:20:46 2020 +0000
@@ -1,6 +1,6 @@
#include "mbed.h"
#include "hcsr04.h"
-#include "Speaker.h"
+#include "Speaker.h"
#include "uLCD_4DGL.h"
HCSR04 distSens(p25,p6);
@@ -8,19 +8,17 @@
Speaker mySpeaker(p18);
uLCD_4DGL uLCD(p9,p10,p11);
-
unsigned int dist;
-
float averageDistance();
void beeping();
float i;
int main()
{
- uLCD.text_width(1); // Normal size
- uLCD.text_height(1); // Normal size
- uLCD.locate(10, 12); // Move cursor
- uLCD.color(BLUE); // Change text color
+ uLCD.text_width(1);
+ uLCD.text_height(1);
+ uLCD.locate(10, 12);
+ uLCD.color(BLUE);
uLCD.printf(" Reverse Sensor");
uLCD.rectangle(65, 117, 126, 127, 0x0000FF);
while(1) {
@@ -29,15 +27,14 @@
beeping();
uLCD.filled_rectangle(66, 118, 125, 127, 0x000000);
pc.printf("cm:%d\n",dist );
- 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.text_width(1);
+ uLCD.text_height(1);
+ uLCD.locate(10, 15);
+ uLCD.color(WHITE);
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**/
+float averageDistance()
{
int a = distSens.get_dist_cm();
int b = distSens.get_dist_cm();
@@ -56,8 +53,8 @@
void beeping()
{
int distance = averageDistance();
-
- if (distance > 2000) i=0.05; //sensor defaults to 2k+ when dist<~3cm
+ //sensor defaults to 2k+ when dist<~3cm
+ if (distance > 2000) i=0.05;
if (distance < 150) i=0.6;
if (distance < 100) i=0.55;
if (distance < 90) i=0.5;
@@ -70,6 +67,5 @@
if (distance < 20) i=0.15;
if (distance < 10) i=0.1;
if (distance < 5) i=0.05;
- mySpeaker.PlayNote(600, i, 5.0);
-
+ mySpeaker.PlayNote(600, i, 5.0);
}
\ No newline at end of file