An auto car with 3 IR sensors.

Dependencies:   Ping

Revision:
4:76b9213714cc
Parent:
3:812a72bbd664
Child:
5:25faf509ee9b
diff -r 812a72bbd664 -r 76b9213714cc main.cpp
--- a/main.cpp	Fri Jun 29 07:47:17 2018 +0000
+++ b/main.cpp	Fri Jun 29 10:14:59 2018 +0000
@@ -37,33 +37,20 @@
     bool left = false;
     bool middle = false;
     bool right = false;
-    
+
     // here I use 500 as threshold
     int threshold = 500;
 
-    while (true) {    
+    while (true) {
         // not on track: > 500
         // on track (black): < 500
         left = leftIR.read_u16() < threshold ? true : false;
         middle = middleIR.read_u16() < threshold ? true : false;
         right = rightIR.read_u16() < threshold ? true : false;
 
-        //led1 = 1; // light on on-board LED
-
         // if middle detects black
         if(middle) {
-            /*if(left && right) { // cliff
-                // stop
-                pc.printf("cliff\r\n");
-                DriveSingleMotor(MOTOR_M1, PWR_STOP, DIR_FORWARD);
-                DriveSingleMotor(MOTOR_M2, PWR_STOP, DIR_FORWARD);
-                // pause for 0.5 sec
-                wait_ms(100);
-
-                // then go backward
-                DriveSingleMotor(MOTOR_M1, 2, DIR_BACKWARD);
-                DriveSingleMotor(MOTOR_M2, 2, DIR_BACKWARD);
-            } else*/ if(left) { // turn left
+            if(left) { // turn left
                 pc.printf("turn left\r\n");
                 DriveSingleMotor(MOTOR_M1, PWR_STOP, DIR_FORWARD);
                 DriveSingleMotor(MOTOR_M2, 2, DIR_FORWARD);
@@ -76,23 +63,7 @@
                 DriveSingleMotor(MOTOR_M1, 2, DIR_FORWARD);
                 DriveSingleMotor(MOTOR_M2, 2, DIR_FORWARD);
             }
-
-            //wait_ms(1000);
         }
-
-        // if all detects white, which means the car is out of track
-        /*if(!middle && !left && !right) { // go backward
-            pc.printf("out of track, go backward\r\n");
-            DriveSingleMotor(MOTOR_M1, 2, DIR_BACKWARD);
-            DriveSingleMotor(MOTOR_M2, 2, DIR_BACKWARD);
-            //wait_ms(1000);
-        }*/
-
-        /*pc.printf("pause\r\n");
-        DriveSingleMotor(MOTOR_M1, PWR_STOP, DIR_FORWARD);
-        DriveSingleMotor(MOTOR_M2, PWR_STOP, DIR_FORWARD);
-        led1 = 0; // turn of on-board LED
-        wait_ms(100);*/
     }
 }