It depends on how you want it to function.
You could run the motor while the button is being pressed
or
one button turns the motor on and one turns it off
or
clicking a button once will turn the motor on and clicking it another time turns it off.
Also your code has some uppercase ‘v’ in vex which should all be lowercase. This might just be a formatting issue. Also next time please note that vexforum as a button for code.
Here are Example of how to do this…
This will run the motor while the button is being pressed and stop when the button is released.
if(controller1.ButtonA.pressing())
{
rob.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct);
}
else rob.spin(vex::directionType::fwd, 0, vex::velocityUnits::pct);
Here one button starts the motor and one stops the motor.
if(controller1.ButtonA.pressing())
{
rob.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct);
}
if(controller1.ButtonB.pressing())
{
rob.spin(vex::directionType::fwd, 0, vex::velocityUnits::pct);
}
Finally you can have a button toggle the motor meaning clicking a button once will turn the motor on and clicking it another time turns it off.
bool clickState = true;
bool motorState = false;
if(controller1.ButtonA.pressing() && clickState)
{
motorState = !motorState;
clickState = false;
}
if(!controller1.ButtonA.pressing()) clickState = true;
if(motorState) rob.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct);
if(!motorState) rob.spin(vex::directionType::fwd, 0, vex::velocityUnits::pct);
In this example clickState is to only do the action once per click, requiring an button release before allowing it again. Then motorState stores the state of the motor: ture is running and false is stoped.