VexCode pro v5 Pneumatics

We are trying to figure how to manage to have 2 pneumatics in our system. This code seems to work with 1 pneumatic in the code, but once we add the second pneumatic it doesn’t work. We have tried a new brain, new solenoid, new driver, everything, and it has fixed nothing. So the problem must be in the code.


#include "vex.h"
 
using namespace vex;
 
bool open=true;
void Clamp1()
{
 open=!open;
}
 
bool open1=true;
void Clamp2()
{
 open1=!open1;
}

int main() {
   vexcodeInit();

 digital_out pneumatic1 = digital_out(Brain.ThreeWirePort.A);
 digital_out pneumatic = digital_out(Brain.ThreeWirePort.C);

  Controller1.ButtonL1.pressed(Clamp1);
 if (open==true)
 {
   pneumatic.set(true);
 }
 else {
   pneumatic.set(false);
 }
 
 Controller1.ButtonR1.pressed(Clamp2);
 if (open1==true)
 {
   pneumatic1.set(true);
 }
 else {
   pneumatic1.set(false);
 }
 }
 

Any suggestions on how to fix this issue would be greatly appreciated.

edit: code tags fixed by mods.

2 Likes

So, I actually was having issues with this earlier. The way someone else helped me fix it was

void PneumaticToggle(){
      pneumatic.set(!pneumaticValue)
}
void Pneumatic1Toggle(){
      pneumatic1.set(!pneumatic1Value)
}

Then in the driver code you would just have

Controller1.ButtonA.pressed(PneumaticToggle);
Controller1.ButtonB.pressed(Pneumatic1Toggle);

also, if they are linked together you can do a splitter.
edit: credit for that fix goes to @xTigr, he was the one who showed it to me

4 Likes