//Movement to press correct button
void pressButton(bool isBlue) {
//After reading the color, make corresponding movements
if(isBlue) {
LCD.WriteLine("BLUE!");
LCD.WriteLine(lightSensor.Value());
//Orient
moveForward(MID_FORWARD, 1.5);
turnRight(90);
turnTo(268);
rightMotor.SetPercent(12);
leftMotor.SetPercent(12);
Sleep(0.3);
moveForward(FAST, 17);
moveForward(-1 * LOW_FORWARD, 3);
rightMotor.SetPercent(100);
Sleep(6.0);
rightMotor.Stop();
//Revert
moveForward(-1 * MID_FORWARD, 7);
turnRight(100);
turnTo(180);
moveForward(MID_FORWARD, 4.5);
} else {
LCD.WriteLine("RED!");
LCD.WriteLine(lightSensor.Value());
//Orient
moveForward(-1 * MID_FORWARD, 6);
turnRight(90);
turnTo(270);
//moveForward(MID_FORWARD,15);
moveForward(FAST, 17);
moveForward(-1 * LOW_FORWARD, 3);
leftMotor.SetPercent(100);
Sleep(6.0);
leftMotor.Stop();
//Revert
moveForward(-1 * MID_FORWARD, 7);
turnRight(60);
turnTo(180);
}
}
Algorithm for pressButton:
- Check if the light is blue, if it is proceed to step 2, if it is not proceed to step 5.
- Orient robot so that it is in front of the blue light.
- Drive forward and hit the blue light with the chassis.
- Revert back to previous position. Proceed to step 8.
- Orient robot so that it is in front of the red light.
- Drive forward and hit the red light with the chassis.
- Revert back to previous position.
- End function.