ECE 4180 / Mbed 2 deprecated 4180_Project

Dependencies:   mbed mbed-rtos SevenSegmentSerial HC_SR04_Ultrasonic_Library

Revision:
6:c8f14de0e3f4
Parent:
5:99be83f824b8
Child:
7:04c8f6b7a42a
diff -r 99be83f824b8 -r c8f14de0e3f4 main.cpp
--- a/main.cpp	Tue Apr 27 16:34:57 2021 +0000
+++ b/main.cpp	Tue Apr 27 17:12:52 2021 +0000
@@ -99,12 +99,12 @@
         width[0] = distance;
         threshold[0] = distance*sensitivity[0];
         setup[0] = !setup[0];
-        pc.printf("Setup: Starting Line\n");
-        pc.printf("Distance: %3d\n\n",distance);
+        //pc.printf("Setup: Starting Line\n");
+        //pc.printf("Distance: %3d\n\n",distance);
     }
 
     if (width[0] - distance >= threshold[0]) {
-        pc.printf("Past starting line\n");
+        //pc.printf("Past starting line\n");
         led0 = 1;
         led1 = 0;
         led2 = 0;
@@ -123,15 +123,16 @@
         width[1] = distance;
         threshold[1] = distance*sensitivity[1];
         setup[1] = !setup[1];
-        pc.printf("Setup: Starting Line\n");
-        pc.printf("Distance: %3d\n\n",distance);
+        //pc.printf("Setup: Starting Line\n");
+        //pc.printf("Distance: %3d\n\n",distance);
     }
 
     if (width[1] - distance >= threshold[1]) {
-        pc.printf("Past Checkpoint 1\n");
+        //pc.printf("Past Checkpoint 1\n");
         led1 = 1;
         track_state = past_cp1;
         pc.putc('1');
+        thread1.start(&play_audio);
     }
 }
 
@@ -142,15 +143,16 @@
         width[2] = distance;
         threshold[2] = distance*sensitivity[2];
         setup[2] = !setup[1];
-        pc.printf("Setup: Starting Line\n");
-        pc.printf("Distance: %3d\n\n",distance);
+        //pc.printf("Setup: Starting Line\n");
+        //pc.printf("Distance: %3d\n\n",distance);
     }
 
-    pc.printf("Past Checkpoint 2\n");
     if (width[2] - distance >= threshold[2]) {
+        //pc.printf("Past Checkpoint 2\n");
         led2 = 1;
         track_state = past_cp2;
         pc.putc('2');
+        thread1.start(&play_audio);
     }
 }
 
@@ -185,12 +187,20 @@
     while(!start_done) {
         if (current_lap) {
             rgbCtrl1 = rgbCtrl2 = rgbCtrl3 = 0;
+            led0 = led1 = led2 = 0;
             rgbRed = 1;
             rgbGreen = 0;
+            bool other = true;
+            speaker.period(1/E5NOTE);
             while (1) {
                 rgbCtrl1 = !rgbCtrl1;
                 rgbCtrl2 = !rgbCtrl2;
                 rgbCtrl3 = !rgbCtrl3;
+                led0 = !led0;
+                led1 = !led1;
+                led2 = !led2;
+                speaker = other ? 0.5 : 0.0;
+                other = !other;
                 if (pc.getc() == 'R') {
                     mbed_reset();
                 }
@@ -217,7 +227,7 @@
         }
         if (current_lap > total_laps) {
             pc.putc('9');
-            pc.printf("Race Over");
+            //pc.printf("Race Over");
             while(1) {
                 if (pc.getc() == 'R') {
                     mbed_reset();