Lu-Hsuan Chen
/
autocar_3sensor_mbed
An auto car with 3 IR sensors.
Diff: main.cpp
- Revision:
- 3:812a72bbd664
- Parent:
- 2:e0a553b64315
- Child:
- 4:76b9213714cc
--- a/main.cpp Fri Jun 29 05:21:46 2018 +0000 +++ b/main.cpp Fri Jun 29 07:47:17 2018 +0000 @@ -48,11 +48,11 @@ middle = middleIR.read_u16() < threshold ? true : false; right = rightIR.read_u16() < threshold ? true : false; - led1 = 1; // light on on-board LED + //led1 = 1; // light on on-board LED // if middle detects black if(middle) { - if(left && right) { // cliff + /*if(left && right) { // cliff // stop pc.printf("cliff\r\n"); DriveSingleMotor(MOTOR_M1, PWR_STOP, DIR_FORWARD); @@ -63,7 +63,7 @@ // then go backward DriveSingleMotor(MOTOR_M1, 2, DIR_BACKWARD); DriveSingleMotor(MOTOR_M2, 2, DIR_BACKWARD); - } else if(left) { // turn left + } else*/ if(left) { // turn left pc.printf("turn left\r\n"); DriveSingleMotor(MOTOR_M1, PWR_STOP, DIR_FORWARD); DriveSingleMotor(MOTOR_M2, 2, DIR_FORWARD); @@ -81,18 +81,18 @@ } // if all detects white, which means the car is out of track - if(!middle && !left && !right) { // go backward + /*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"); + /*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); + wait_ms(100);*/ } }