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:
- 15:827fbc2e07d6
- Parent:
- 14:88c09f96bdda
- Child:
- 16:5250c9fe0408
diff -r 88c09f96bdda -r 827fbc2e07d6 main.cpp
--- a/main.cpp Fri Apr 24 23:16:46 2020 +0000
+++ b/main.cpp Sun Apr 26 04:16:17 2020 +0000
@@ -11,7 +11,7 @@
uLCD_4DGL uLCD(p13, p14, p12); // Initialize uLCD serial tx, serial rx, reset pin;
-SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
+//SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
RawSerial blue(p9,p10); //Initialize Blutooth
//Serial BT(p9,p10);
@@ -36,6 +36,11 @@
};
float duration[2]= {1, 0.0
};
+
+volatile int values[5] = {0,0,0,0,0};
+volatile int index = 0;
+volatile bool allZero = true;
+int state = 0;
void sonar(int distance)
@@ -43,7 +48,22 @@
//put code here to execute when the sonar distance has changed
dist.lock();
sdist = distance;
+ values[index] = distance;
dist.unlock();
+
+ index++;
+ if (index > 4)
+ {
+ index = 0;
+ }
+
+ allZero = true;
+ for (int i = 0; i < 5; i++){
+ if (values[i] != 0)
+ {
+ allZero = false;
+ }
+ }
//printf("Sonar Distance:\r\n %d", sdist);
}
@@ -225,7 +245,18 @@
//Loop to validate the main loop is executing
while(1) {
+
+ //this 'state machine' should make sure that individuals are only counted once
+ if ((state != 1) && !allZero){
+ state = 1;
+ //do logic to figure out direction
+ //right now just adding to main counter
+ counter++;
+ }
+ if (state == 1 && allZero){
+ state = 0;
+ }
//MyLED = !MyLED;
- //Thread::wait(100);
+ Thread::wait(100);
}
}
\ No newline at end of file