Andres Rodriguez / Mbed 2 deprecated Collision_Avoidance_Robot-Controller

Dependencies:   mbed mbed-rtos 4DGL-uLCD-SE

Revision:
1:0b28ff74c547
Parent:
0:a0902c8e1f7b
diff -r a0902c8e1f7b -r 0b28ff74c547 main.cpp
--- a/main.cpp	Fri Apr 26 14:24:41 2019 +0000
+++ b/main.cpp	Fri Apr 26 14:53:26 2019 +0000
@@ -1,25 +1,20 @@
 #include "mbed.h"
 #include "uLCD_4DGL.h"
-#include "rtos.h"
 #include "stdio.h"
 #include <cstdlib>
 #include "math.h"
-
-//#define MIN_DIST = ?????
-
-Mutex uLCD_mutex;
+#include "Speaker.h"
 
 DigitalOut myled(LED1);
 
-Serial hc05(p9, p10); //master HC05 bluetooth, *CHECK PINS*
+Serial hc05(p9, p10); //master HC05 bluetooth
 Serial pc(USBTX, USBRX); //serial pc connection for testing, *ONLY USE WHEN TESTING*
 
-uLCD_4DGL uLCD(p28, p27, p11); //uLCD for lidar imaging, *CHECK PINS*
-AnalogOut speaker(p18); //speaker for collision detect noise
+uLCD_4DGL uLCD(p28, p27, p11); //uLCD for lidar imaging
+Speaker mySpeaker(p18); //speaker for collision detect noise
 
-AnalogIn horz(p16); //left/right input from joystick, *CHECK PINS*
-AnalogIn forward(p15); //forward input from joystick, *CHECK PINS*
-//DigitalIn stop(p17); //stop input from joystick, *CHECK PINS* 
+AnalogIn horz(p16); //left/right input from joystick
+AnalogIn forward(p15); //forward input from joystick
 
 volatile int mode = 0; //drive mode = 0 or collision detect mode = 1
 
@@ -125,11 +120,12 @@
             if(good_buff){ mode = 1; }                              /* SET MODE */
                             
 
-            if (mode) {
+            if (mode) {                         /* COLLISION AVOIDANCE PROTOCOL */
                 /* pc.printf("Collision Avoidance Engaged\r\n"); */
                 uLCD.cls();                                /* INIT RADAR SCREEN */
                 uLCD.filled_circle(64, 64, 5, (RED+GREEN)); 
-                Thread::wait(2*1000);
+                mySpeaker.PlayNote(440, 1000, 0.8);                /* PLAY TONE */
+                Thread::wait(1000);                     /* WAIT AN EXTRA SECOND */
                 ack_timer.start();
                 int i = 0;
                 while(i < 60) {
@@ -178,9 +174,7 @@
                         int y = (int) (64.0f + (collision_dist * 60 * sin(collision_angle)));
     
                         if (x >= 0 && y >= 0) {
-                            uLCD_mutex.lock();
                             uLCD.filled_circle(x, y, 2, GREEN);
-                            uLCD_mutex.unlock();
                         }
                     } else if(ack_timer.read_ms() > 2000) {
                         hc05.printf("_ack_%02d", (i-1));         /* ACKNOWLEDGE */