Toggle in vexcode pro

Button.pressing() returns a boolean (true/false) status of the button at that moment. This can be continuously evaluated inside of a while loop and works well for a driver to control motors.

while(true) {
   if(button1.pressing()) {
      motor1.spin(forward);
   }
}

Button.pressed(DoSomething) fires an event when the button is pressed. This example calls the DoSomething() function one time and will not call it again until the button is released and pressed again. Events are great if you want to robot to do a subset of commands.

void DeployEndgame()
{
    motor1.spinTo(90, degrees);
    motor2.spinTo(30, degrees);
}

int DriverControl(){

   //register button event
   button1.pressed(DeployEndgame);

   while(true) {
     //Code to operate robot.
   }
}
5 Likes