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: 4DGL-uLCD-SE SDFileSystem ShiftBrite mbed-rtos mbed wave_player Motor
Diff: main.cpp
- Revision:
- 6:21c5a7cf63de
- Parent:
- 5:6ca141fc6c4e
- Child:
- 7:df218a6a1a01
--- a/main.cpp Wed Mar 15 05:45:22 2017 +0000
+++ b/main.cpp Wed Mar 15 07:09:20 2017 +0000
@@ -26,6 +26,7 @@
AnalogIn IR(p20);
//RawSerial BT(p9, p10); //bluetooth pinout
FILE *wave_file = NULL; //global bc its gotta be changed by Main while running in child thread
+FILE *wave_file2 = NULL;
wave_player waver(&DACout); //create wave_player object for speaker
void LCD_thread1() {
@@ -45,13 +46,24 @@
//FILE *wave_file;
wave_file=fopen("/sd/vacuum.wav","r");
if (wave_file == NULL){
- led1=led2=led3=led4 = 1; // if file read error, all LEDs ON
+ led1=led4 = 1; // if file read error, outside LEDs are on
+ led2=led3 = 0;
}
waver.play(wave_file);
fclose(wave_file);
}
}
+void beep(){
+ wave_file2=fopen("/sd/beep.wav","r");
+ if(wave_file2 == NULL) {
+ led1=led4 = 0; // if file read error, inside LEDs are on
+ led2=led3 = 0;
+ }
+ waver.play(wave_file2);
+ fclose(wave_file2);
+}
+
int main() {
//thread1.start(IR_thread); // read in IR data
thread2.start(LCD_thread1);
@@ -69,8 +81,21 @@
} else if (IR>0.7 && IR<0.9) {
led1=led2=led3=1;
led4=0;
- } else if (IR>0.95) { //collision threshold seems to be the same from IR=0.8 to IR=0.95
- led1=led2=led3=led4=1;
+ } else if(IR>0.9){ //collision threshold seems to be the same from IR=0.8 to IR=0.95
+ led1=led2=led3=led4=1;
+ fclose(wave_file);
+ thread4.terminate();
+ thread4.start(beep);
+ /* reverse motors and turn Roomba here
+ *
+ *
+ *
+ *
+ */
+ wait(5); //wait for beeping to finish
+ fclose(wave_file2);
+ thread4.terminate();
+ thread4.start(sound_thread);
} else led1=led2=led3=led4=0;
}
// use mutex to lock getc(), printf(), scanf()
