Hey guys,
I’m just wrapping up the programming here. I’m using V5 Pro (yes, I know we should be using VS Code, but we’re running out of time). Anyway, I think the Code is right—there are no programming issues, but the pneumatics do not engage. Is there anything I’m doing wrong? I’ve got the comp. template but I don’t know what to do.
Looking at your code, it looks like your put your code where main() is supposed to be, put it in user control which is where it should be. It would be great if you can post your entire code so we can be sure.
Main is just for setting up callbacks like preauton, auton, and user control so field control can run it.
So, do you want the solenoid to only actuate while holding down the button, or do you want it to be a activate when pressed? There are two different methods for this, depending on what you want:
Method 1: Holding Down while Pressed
The way you would go about holding the button down to keep the pneumatics actuated would look something like this:
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
if(Controller1.ButtonA.pressing())
{
Piston.set(true);
waitUntil(!Controller1.ButtonA.pressing());
Piston.set(false);
}
}
Here’s how it works:
The pressing() method checks to see if the button is currently being pressed. The pressed() method, on the other hand, is a callback to another function. Once the button is being held, the piston is extended and the function waits until the button is released to retract the piston. This is ineffective, as it holds up the entire program until the button is released. there are most likely other ways to do such a thing, but I lack the knowledge.
Method 2: Press Button to Actuate (The way most do it)
This is a bit more complicated, as it involves setting up a callback function, but here’s an example:
void whenButtonAPressed()
{
//extends piston
Piston.set(true);
}
void whenButtonBPressed()
{
//retracts piston
Piston.set(false);
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
//setting up callback
Controller1.ButtonA.pressed(whenButtonAPressed);
Controller1.ButtonB.pressed(whenButtonBPressed);
}
Here’s how this one works:
The pressed() function sets up a callback to another function that executes when the callback is triggered. This is the purpose of the two void functions above the main method. It is a requirement that the callback functions be above the callbacks. There are also two callbacks, one for an extension and one for a retraction. If you want a single button toggle, there are forum posts out there for it. Just search for Vexcode Pro Button Toggle or something similar.
Hope these help!
Luke, 16756A
I’ll try it!
Thanks a lot!
7192J