Help with Pressed Function

Hello Vex Forums,
I have successfully coded my robot, but I am looking to improve on it. Right now we have a catapult bot where if you hold a button, the catapult goes down. However, I am looking to make it so that I can click the button once instead of having to hold it. We have a limit switch so we know when it will stop, I know of a shaft encoder, but we are not using it. Our current catapult bot code is:
//Catapult Code
if (Controller1.ButtonR2.pressing() and Lim.pressing() == false) {
Catapult.spin(directionType::fwd,100,velocityUnits::rpm);
}
if (Lim.pressing()){
Catapult.spin(directionType::fwd, 10, velocityUnits::rpm);
}
if (Controller1.ButtonR1.pressing() and Lim.pressing()){
Catapult.spin(directionType::fwd,100,velocityUnits::rpm);
}

I am wondering how to use the pressed command. When I replace the first lines pressing with:
if (Controller1.ButtonR2.pressed(){
Catapult.spin(directionType::fwd,100,velocityUnits::rpm);
}
It pops up with an error and doesn’t compile properly.
If anyone has a solution to the pressed function, please share on how to use it I am lost on this.

With Best Regards,
6722C

You call pressed once before your while(true) loop. It sets up a thread to watch for the event that the button is pressed, and then it calls the function you’ve got attached to it.

void catapultCode(void) {
\ stuff
}

Then in operator control before while(true):

Controller1.ButtonR2.pressed(catapultCode);

@callen would you need an if statement, or is it already like an if where if its clicked once it runs the function

If the button is clicked, it will run the specified function.

I would recommend creating a “reloaded” boolean or something that when false just spins the motor forward (which is what your shoot button currently does), and when true just keeps the catapult still. When it hits the limit switch, switch the boolean to true (so the motor stops moving the catapult forward and just holds it in position). After that, just have the shoot button set the catapult motor forward and set the reloaded boolean to true so the catapult can fire and automatically reload itself.

If you guys need more help, I’ll see you guys on Saturday :).