Cynthia Wang / Mbed 2 deprecated ECE4180-FinalProject

Dependencies:   mbed-rtos mbed Servo Motor SoftPWM

Revision:
9:0b045f2791ea
Parent:
8:c54f1cfcbfe0
Child:
10:3deaf72fa257
--- a/main.cpp	Thu Nov 17 21:41:57 2022 +0000
+++ b/main.cpp	Thu Nov 17 22:17:31 2022 +0000
@@ -21,7 +21,7 @@
 BusOut lives_leds(p5, p6, p7);
 
 // Speaker
-PwmOut speaker(p25);
+AnalogOut speaker(p25);
 
 volatile float speed_left = 0;
 volatile float speed_right = 0;
@@ -71,16 +71,19 @@
     // IR setup
     //Drive IR LED data pin with 38Khz PWM Carrier
     //Drive IR LED gnd pin with serial TX
+    Thread::wait(1000); //Let other PWM threads initialize
     IRLED.period(1.0/38000.0);
     IRLED = 0.5;
     ir_device.baud(2400);
     while(1) {
-        if(ir_device.readable()) {
+        while (!ir_device.readable()) Thread::wait(0);
+        char c = ir_device.getc();
+        if (c == 'f') {   
             rx_led = 1;
-            pc.putc(ir_device.getc());
+            pc.putc(c);
             decrease_lives();
             rx_led = 0;
-        }  
+        }
     }
 }