Pneumatic One Way Cylinders Toggle

Heyo, I’m having trouble with my Pneumatics. When I hit the toggle the first time, they will extend, but when I hit it the second time, they will briefly release, but they won’t stay released.
Here’s the gists of the code

bool PneumaticsON = false;
void Pnematics(){
     if (PneumaticsON == false){
           PneumaticsON = true;
     }
    else {
          PneumaticsON = false;
    }
}

Then in my driver code I say

Controller1.ButtonA.pressed(Pneumatics);
if (PnematicsON == true){
    BackLift.set(true);
}
else{
    BackLift.set(false);
}

Any idea on why that toggle isn’t working?

I would like to mention that we have triple checked the building side, and it even works if I do

if (Controller1.ButtonA.pressing()){
    BackLift.set(true);
}
else{
    BackLift.set(false);
}

You could try doing something like this

void toggleBackLift(){
  BackLift.set(!BackLift.value());
}
Controller1.ButtonA.pressed(toggleBackLift);
1 Like

Put this OUTSIDE of any loop (pre auton, auton, driver control) just put it somewhere in between them:

int toggleClamp () {

bool GoalClampState = false;
bool GoalClampLast = false;

while (true) {
  
  if (MainController.ButtonB.pressing () == true && !GoalClampLast) {
    GoalClampState = !GoalClampState;
    GoalClampLast = true;
  }

  else if (!MainController.ButtonB.pressing () == true) {
    GoalClampLast = false;
  }

  if (GoalClampState) {
    DigitalOutH.set (true);
  }

  else {
    DigitalOutH.set (false);
  }
task::sleep (50);
}

return 1;
}

Put this in Driver Control:
task toggleClampTask (toggleClamp);

This might not work for your code, but its what I use for mine and it works perfectly.

1 Like

This one worked perfectly, thank you! Out of curiosity, why didn’t the original toggle work?

Not completely sure why your code didn’t work but its probably because your code loops so many times that its detecting the button being pressed multiple times before you release it, so that’s probably why it didn’t work. Example: Presses “A” Button for .2 seconds, Code has looped 16 times (not sure how many times per second the code loops so this is just an estimate) in that time which breaks your loop, and the toggle doesnt work.

Ahh, I see, thank you for your help!

I’m not really sure, it might have something to do with registering the button pressed callbacks multiple times in a loop. Or it might be due to the typo in the function definition.

1 Like

void togglepneumatic();
pneumatic.set(!pneumatic.value());
}
Controller1.ButtonRight.pressed(PneumaticToggle);

can anyone tell me why this isnt working
it says that the controller doesnt work

void togglepneumatic(){
  pneumatic.set(!pneumatic.value());
}
Controller1.ButtonRight.pressed(togglepneumatic);
2 Likes