Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 1:ecbf974d0733
- Parent:
- 0:190c4784b6f4
- Child:
- 2:e0a553b64315
diff -r 190c4784b6f4 -r ecbf974d0733 main.cpp
--- a/main.cpp Wed Jun 27 16:23:33 2018 +0000
+++ b/main.cpp Thu Jun 28 07:30:44 2018 +0000
@@ -63,12 +63,12 @@
DriveSingleMotor(MOTOR_M2, 2, DIR_BACKWARD);
} else if(left) { // turn left
pc.printf("turn left\r\n");
+ DriveSingleMotor(MOTOR_M1, PWR_STOP, DIR_FORWARD);
+ DriveSingleMotor(MOTOR_M2, 2, DIR_FORWARD);
+ } else if(right) { // turn right
+ pc.printf("turn right\r\n");
DriveSingleMotor(MOTOR_M1, 2, DIR_FORWARD);
DriveSingleMotor(MOTOR_M2, PWR_STOP, DIR_FORWARD);
- } else if(right) { // turn right
- pc.printf("turn right\r\n");
- DriveSingleMotor(MOTOR_M1, PWR_STOP, DIR_FORWARD);
- DriveSingleMotor(MOTOR_M2, 2, DIR_FORWARD);
} else { // go straight
pc.printf("go straight\r\n");
DriveSingleMotor(MOTOR_M1, 2, DIR_FORWARD);
@@ -79,7 +79,7 @@
}
// 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);