bool toggle = false;
if (Bumper.pressing){
if (!(toggle)){
toggle = true;}
else if (toggle){
toggle = false;}
while (Bumper.pressing){
wait(1, msec);}}
if (toggle){
motor.spin();}
else if (!(toggle)){
motor.stop();}
Here is what I have using your program. I’m still not successful. Is there anything you see that would be causing an issue? All my ports are in the correct location and tested using a working program.
int main(){
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
bool toggle = false;
if (BumperA.pressing()) {
if (!(toggle)) {
toggle = true;
}
else if (toggle) {
toggle = false;
}
while (BumperA.pressing()) {
wait(1, msec);
}
}
if (toggle){
leftMotor.spin(forward);
} else if (!(toggle)) {
leftMotor.stop();
}
}
You do need a while loop around the whole code so it continues to run the program. I think that you also need a latch to prevent the toggle from flipping back and forth over every loop.
int main(){
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
bool toggle = false;
bool latch = false;
while(true){
if (toggle){
leftMotor.spin(forward);
} else {
leftMotor.stop();
}
if (BumperA.pressing()) {
if(!latch){ //flip the toggle one time and set the latch
toggle = !toggle;
latch = true;
}
} else {
//Once the BumperA is released then then release the latch too
latch = false;
}
wait(20, msec);
}