James Plager / Mbed 2 deprecated Roomba_Project

Dependencies:   4DGL-uLCD-SE SDFileSystem ShiftBrite mbed-rtos mbed wave_player Motor

Revision:
10:059154e51621
Parent:
9:37bb5f0e2975
Child:
11:9d9ab1dfa28a
--- a/main.cpp	Thu Mar 16 03:39:30 2017 +0000
+++ b/main.cpp	Thu Mar 16 06:48:56 2017 +0000
@@ -6,7 +6,7 @@
 #include "wave_player.h"
 #include "Motor.h"
 
-Mutex mutex;    //
+Mutex mutex;    // make sure only one thread trying to write to uLCD at a time
 Mutex mutex2;   //
 DigitalOut led1(LED1);
 DigitalOut led2(LED2);
@@ -40,7 +40,36 @@
         mutex.unlock();
         wait(.5);
     }     
+}
+//LCD fucntions to display status
+void LCD_GRN(){
+    //mutex.lock();
+    uLCD.cls();         // clear scrn
+    uLCD.background_color(GREEN);     
+    uLCD.locate(7,7);        // place cursor middle of screen
+    uLCD.printf("GOOD");
+    
+    //mutex.unlock();             //free mutex
 } 
+void LCD_YEL(){
+    //mutex.lock();
+    uLCD.cls();
+    uLCD.background_color(YELLOW);     
+    uLCD.locate(4, 8);        // place cursor middle of screen
+    uLCD.printf("Collision");
+    uLCD.locate(4,9);
+    uLCD.printf("Imminent");
+    //mutex.unlock();
+}
+void LCD_RED(){
+    //mutex.lock();
+    uLCD.cls();
+    uLCD.background_color(RED);   
+    uLCD.textbackground_color(BLACK);  
+    uLCD.locate(2, 8);        // place cursor middle of screen
+    uLCD.printf("REVERSING");    
+    //mutex.unlock();
+}
 void sound_thread(){
     while(1) {
         //FILE *wave_file;
@@ -86,30 +115,39 @@
     Right.speed(0.0);
 }
 
-
 int main() {
     Left.speed(0.0);        //attempt at forcing Left to chill on startup. ineffective.
     Right.speed(0.0);       //Right does not have the issue. Is chill on startup
     //thread1.start(IR_thread); // read in IR data
-    thread2.start(LCD_thread1);   
+    //thread2.start(LCD_thread1);   
     //thread3.start(Motor_thread);
     thread4.start(sound_thread);
     
     float turnDirectionSelector = 0.3;
     drive(0.3);    // begin driving fwd    
+    //thread1.start(LCD_GRN);           // I think when thread closes, LCD reverts to black.
+    LCD_GRN();
+    //bool screenNotWritten = false;
     while(1){        
         //IR testing
-        if(IR>0.3 && IR<0.5) {              // scan for object
+        if(IR>0.3 && IR<0.5) {
+            LCD_GRN();              // scan for object
             led1=1;
             led2=led3=led4=0;
         } else if (IR>0.5 && IR< 0.7) {
+            //thread2.start(LCD_YEL);
+            LCD_GRN();
             led1=led2=1;
             led3=led4=0;
         } else if (IR>0.7 && IR<0.9) {
+            LCD_YEL();
             led1=led2=led3=1;
             led4=0;
         } else if(IR>0.9){ //collision threshold seems to be the same from IR=0.8 to IR=0.95
                             // in this block, "collision" detected. Back up, execute turn, and proceed driving fwd.
+            //thread3.start(LCD_RED);
+            
+            //LCD_RED();
             led1=led2=led3=led4=1; 
             fclose(wave_file);
             thread4.terminate();
@@ -124,11 +162,13 @@
             wait(1);    //2s is a bit more than 180deg @ 0.3 speed
             stop();
             
-            wait(2); //wait for beeping to finish
+            wait(0.7); //wait for beeping to finish
+            
             fclose(wave_file2);
             thread4.terminate();
             thread4.start(sound_thread);
             drive(0.4);
+            //thread1.start(LCD_GRN);
         } else led1=led2=led3=led4=0;
     }
 }
\ No newline at end of file