I need to get my robot to be able to use the bump switches so that either one can be pressed and the motor corresponding to that bumpswitch will run for as long as the bump switch is pressed. The problem I'm having is getting the LEDs to light up correctly. While the bump switch code block is running, I need the LEDs to light up and go off seven times for one second every time the Light sensor value gets higher than 400. How do I do it? Please Help! My Code is posted below:
#pragma config(Sensor, in2, lightSensor, sensorReflection)
#pragma config(Sensor, dgtl3, bumpSwitch, sensorTouch)
#pragma config(Sensor, dgtl4, bumpSwitch2, sensorTouch)
#pragma config(Sensor, dgtl10, ledGreen, sensorLEDtoVCC)
#pragma config(Sensor, dgtl11, ledRed, sensorLEDtoVCC)
#pragma config(Motor, port1, leftMotor, tmotorVex269, openLoop)
#pragma config(Motor, port10, rightMotor, tmotorVex269, openLoop)
task main() {
while(true) {
if (SensorValue(lightSensor) > 400) {
int count = 0;
while (count < 7) {
turnLEDOn(ledGreen);
turnLEDOn(ledRed);
wait(1);
turnLEDOff(ledGreen);
turnLEDOff(ledRed);
count++;
}
}
while (SensorValue(bumpSwitch) == 0 && SensorValue(bumpSwitch2) == 0) {
stopMotor(rightMotor);
stopMotor(leftMotor);
}
while (SensorValue(bumpSwitch2) == 1) {
startMotor(rightMotor, 55);
startMotor(leftMotor, 55);
}
while (SensorValue(bumpSwitch) == 1){
startMotor(rightMotor, -55);
startMotor(leftMotor, -55);
}
}
}