VEX C++ Programming Pneumatics

Like this. You may need to reverse logic.
This uses the last three wire port, change as necessary.

digital_out dig1 = digital_out( Brain.ThreeWirePort.H );

int main() {
  int count = 0;

  while(1) {
    if( Controller1.ButtonL1.pressing() ) {
      dig1.set( true );
    }
    else {
      dig1.set( false );
    }

    this_thread::sleep_for(10);
  }
}
8 Likes

Thank You for giving some example code!

Thank you! much appreciated, helped our E team out a lot.

I wounder what you guys are using pneumatics for. If you still need help with the programming we just got ours all good. I can send code if you need

I tried using this code but it did not work. is there something in motor centers set up I have to do?

nothing else to do.
pneumatics driver should be plugged into port H on the V5 brain.
Are you using VCS or VEXcode ?

What is vcs is that required? And how is it different from vex code

VCS = VEX coding studio, programming IDE for the VEX V5 system.

VEXcode, a new text only programming environment for the VEX V5 system.

This topic was discussing programming pneumatics on the V5 using Vex coding studio, so I assume that’s what you are using.

Hello I have a question, so Is this for vex c++ or c++ pro?

It will function the same regardless

Hello sorry for bothering u but how will the pneumatic retract

If you can add some code please do just as an example

In the code from jpearman the L1 button extends and letting go of the button retracts it. (Or vice versa - you’ll have to test it)

void usercontrol( void ) {
//

int LiftLSpeedPCT = 100;
int LiftRSpeedPCT = 100;

while (1){
//tank controls
BackR.spin(directionType::fwd, (Controller1.Axis2.value()), vex::velocityUnits::pct);
BackL.spin(directionType::fwd, (Controller1.Axis3.value()), vex::velocityUnits::pct);
FrontL.spin(directionType::fwd, (Controller1.Axis3.value()), vex::velocityUnits::pct);
FrontR.spin(directionType::fwd, (Controller1.Axis2.value()), vex::velocityUnits::pct);

  digital_out dig1 = digital_out( Brain.ThreeWirePort.Port[7] );

while(1) {
if( Controller1.ButtonR1.pressing() ) {
dig1.set( true );
}
else {
dig1.set( false );
}

this_thread::sleep_for(10);

}
}

 //lIFT Control
  if(Controller1.ButtonL1.pressing()) {
      LiftL.spin(vex::directionType::fwd, LiftLSpeedPCT, vex::velocityUnits::pct);
      LiftR.spin(vex::directionType::rev, LiftRSpeedPCT, vex::velocityUnits::pct);
  }
  else if(Controller1.ButtonL2.pressing()) {
      LiftL.spin(vex::directionType::rev, LiftLSpeedPCT, vex::velocityUnits::pct);
      LiftR.spin(vex::directionType::fwd, LiftRSpeedPCT, vex::velocityUnits::pct);
  }
  else {
      LiftL.stop(vex::brakeType::coast);
      LiftR.stop(vex::brakeType::coast);
    }   

vex::task::sleep(20); //Sleep the task for a short amount of time to prevent wasted resources. 

}

1 Like

this is my code and its not letting me control the bot whats wroooong

This right here is an infinite loop. the rest of your code is not executing. It’s already in a while loop, so you shouldn’t need another one for this if statement.

Additionally, your ‘LIFT CONTROL’ is outside the scope of your larger, still infinite, while loop. That code also needs to be in the loop to run

void usercontrol( void ) {
//

int LiftLSpeedPCT = 100;
int LiftRSpeedPCT = 100;

while (1){
//tank controls
BackR.spin(directionType::fwd, (Controller1.Axis2.value()), vex::velocityUnits::pct);
BackL.spin(directionType::fwd, (Controller1.Axis3.value()), vex::velocityUnits::pct);
FrontL.spin(directionType::fwd, (Controller1.Axis3.value()), vex::velocityUnits::pct);
FrontR.spin(directionType::fwd, (Controller1.Axis2.value()), vex::velocityUnits::pct);

  digital_out dig1 = digital_out( Brain.ThreeWirePort.Port[7] );

if( Controller1.ButtonR1.pressing() ) {
  dig1.set( true );
}
else {
  dig1.set( false );
}

this_thread::sleep_for(10);
  
 
  if(Controller1.ButtonL1.pressing()) {
      LiftL.spin(vex::directionType::fwd, LiftLSpeedPCT, vex::velocityUnits::pct);
      LiftR.spin(vex::directionType::rev, LiftRSpeedPCT, vex::velocityUnits::pct);
  }
  else if(Controller1.ButtonL2.pressing()) {
      LiftL.spin(vex::directionType::rev, LiftLSpeedPCT, vex::velocityUnits::pct);
      LiftR.spin(vex::directionType::fwd, LiftRSpeedPCT, vex::velocityUnits::pct);
  }
  else {
      LiftL.stop(vex::brakeType::coast);
      LiftR.stop(vex::brakeType::coast);
    }   

vex::task::sleep(20); //Sleep the task for a short amount of time to prevent wasted resources. 

}
}

last question would this work is there any problem, i cant test on my bot till next week thats why im asking

I don’t see any issues with it :smile:

how would this be programmed in autonomous