Robot that currently does nothing
Dependencies: 4DGL-uLCD-SE SDFileSystem ShiftBrite mbed-rtos mbed wave_player Motor
Revision 6:21c5a7cf63de, committed 2017-03-15
- Comitter:
- CRaslawski
- Date:
- Wed Mar 15 07:09:20 2017 +0000
- Parent:
- 5:6ca141fc6c4e
- Child:
- 7:df218a6a1a01
- Commit message:
- added beep thread, if IR sensor detects prox vacuum thread is terminated and beeping thread begins. Runs for 5 seconds as a placeholder for Roomba backing up and turning, then resumes vacuuming
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- 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()