Im using legacy double-action pneumatics from scm and solenoids with three wire inputs going into the brain. How can I code them so that when I press a button on the controller, it toggles the pneumatics on/off instead of having a dedicated button for on and off? (Im using vexcode v5)
Here’s what this code would look like in blocks!
As for an explanation, when you start the program you can use a custom variable to save the state of your pneumatic pistons. Using the “When controller1” hat block and following it with a “if then” statement using that value you made earlier “Piston_Status”. 0 in this scenario represents the pneumatic pistons being off thus when the status is 0, the pistons are set low and the status is set to 1 and vise versa.
Hope this helped!
1 Like
for text, just use an event handler and the .value()
operator.
int main() { //yes, put the event handler in main. This ensures it will only register once.
controller(primary).Button_.pressed([]() { //this weird syntax is called a lambda.
//It's essentially just a temporary function so you don't have do declare it anywhere else just to
//use it once.
piston.set(!piston.value()); //setting it to the opposite of whatever the previous value was.
//For example, if the previous value was true, the ! operator will return false.
//The piston.set() function will then set the piston's state to the returned value.
});
}
2 Likes
Alternatively, in C++ it’s very simple.
Cylinder.set(!Cylinder.value());
2 Likes
Thank you guys. All of it helped!
2 Likes
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.