Coding Pneumatics
Last updated
Was this helpful?
Last updated
Was this helpful?
Pneumatics can be intimidating at first, but the code for them is simple. In this tutorial, we'll show you how to make a toggle button for a pneumatic piston on the robot.
Start by setting up the pneumatic in VEXCode Pro. It's a 3-wire DigitalOut device:
--->
Now, we need to make a variable storing whether or not the pneumatic piston is current active or not. We'll use a boolean variable and set it to false by default. This variable should be defined outside of all functions, below the #include "vex.h";
and using namespace vex;
lines of code.
Next, we'll make a function that toggles the pneumatic piston on or off. This function flips the pneumaticActive
variable first, and then either activates or deactivates the pneumatic based on the value of the pneumaticActive
variable.
Lastly, we have to set up a callback for the togglePneumatic function, so it is run when a button is pressed. Put the following code in the main function, like so:
That's it! Now you have code that activates and deactivates the pneumatics at the press of a button!