Button Toggle - Vex Code

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);
}
8 Likes