Ascend
Coding
Ascend
  • 🚀Introduction
  • VEX Robotics
    • 🛠️Building
      • 📏CAD Design
      • 🔧Best Practices
      • 🏎️Drive Trains
        • 🔩Screw Joints
        • 🥊Boxing
        • 🔵Bearing flats
        • 🛤️Fixing Friction
        • 🔥450 RPM on 2.75"
      • 🏍️Motors
      • 🪨Metal
      • Plastic
      • 🎈Pneumatics
      • ➕Additional Mechanisms
        • 🖨️3D Printing
        • ↔️Ratchets
        • 🏹Catapults
        • 🎣Intakes
        • 🏋️Lifts
    • 💻Coding
      • ⚖️Choosing Your Coding Environment
      • 🔴VEXCode Pro
        • 🖥️Getting Started
        • 🚗Drive Code
        • 🚴Coding Motors
        • 🌬️Coding Pneumatics
        • 🎛️Advanced
          • 📡Coding Autonomous
          • 📈Coding PIDs
            • ⬆️Drive PID Tutorial
            • ↩️Turn PID Tutorial
            • 🎸Tuning PIDs
              • 🔢Ziegler-Nichols Method
              • 📊Graphing PIDs
          • 📋Tasks
          • 🚝Advanced Drive Code
      • 🟡PROS
    • 📗Engineering Notebook
      • 📔Formatting
      • ⭐Notebook Walkthrough
      • 💠Decision Matrices
        • 📌Decision Point
      • ➕Additional Resources
    • 🏆Tournaments
      • 🗣️Team Interviews
        • 🪙Interview Tips
        • ⛳Interview Scoring
        • 🤽‍♀️Interview Practice Questions
      • 🤹Skills
      • ℹ️Ranking and Stats
      • 📷Filming Matches
  • Other
    • 🧑‍💼Management
      • 🕑Time Management
      • 👨‍👩‍👧‍👦Team Management
        • 👮Delegation
        • ⚓Optimal Team Size
      • 🖇️Code Management (GitHub)
      • 🚋Resource Management
      • ⁉️Stuck?
    • 🍎Physics
      • ⚙️Torque
      • 😑Stress Forces
    • 👾Extra stuff
      • 📸96504 Gallery
      • ⛑️VEX Team Resources (High Stakes)
      • 🏎️Driving Simulator
Powered by GitBook
On this page

Was this helpful?

  1. VEX Robotics
  2. Coding
  3. VEXCode Pro

Coding Pneumatics

PreviousCoding MotorsNextAdvanced

Last updated 11 months ago

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.

//global variables
bool pneumaticActive = false; //true or false, whether or not the pnuematic is active

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.

//toggle the pneumatic piston on or off
void togglePneumatic() {
  pneumaticActive = !pneumaticActive; //flip the on/off variable
  
  if (pneumaticActive) {
    Pneumatic.set(true); //Activate the pneumatic
  } else {
    Pneumatic.set(false); //Deactivate the pneumatic
  }
}

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:

int main() {
  //Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();
  
  //Set up the pneumatic toggle callback
  Controller1.ButtonX.pressed(togglePneumatic); 

  //there may be more code below, leave it be
}

That's it! Now you have code that activates and deactivates the pneumatics at the press of a button!

💻
🔴
🌬️