So currently to activate the pneumatics i have to press and hold the button I want to make it where I just press it
Could you clarify a bit? Maybe post a picture of the code? I’m not exactly sure what the problem is. Also, if you use the search bar, you can find plenty of topics already about pneumatics coding. Try reading some of those to see if they can help you.
Are you using vex pro or the block code?
i am using vex pro for my code
if( Controller1.ButtonL2.pressing() ) {
piston.set( false );
}
//Otherwise don’t activate
else {
piston.set( true );
}
i want to use pressed instead of pressing
This should work and then have a button for true
Void( Controller1.ButtonL2.pressing() ) {
piston.set( false );
}
it currently works but we have to hold the button to fully extend the piston
This is what my team did last year
bool PnuematicsPressed = false;
while (true) {
if (Controller1.ButtonY.pressing()){
if (PnuematicsPressed){
piston.set(false);
PnuematicsPressed = false;
} else {
piston.set(true);
PnuematicsPressed = true;
}
}
}
It’s a bit of a work around. There’s probably a better way to do it but this worked for us.
Also, whenever you post code, enclose it in ```
The code above will not work as expected. It will just rapidly switch between setting the piston to true and false until you let go of the button. The part you are missing is a variable to make sure you only run this section whenever it is a new button press, not a held button.
An example of this is below
bool last_value = false;
bool pnuematic_toggle = false;
bool current_value = false;
while(true) {
current_value = Controller1.ButtonY.pressing();
// if this current loop detects a new button press, toggle the pnuematic
if(current_value && current_value != past_value) {
pnuematic_toggle = !pneumatic_toggle // switch the value of pnuematic value
piston.set(pnuematic_toggle);
}
past_value = current_value;
}
We ended up just adding a delay actually to our code so it wouldn’t rapidly switch. I just forgot to put that in when I wrote that. Your solution is way better @BennyBoy. I might even end up using that instead of the method we used last year.
This is how I would use pressed (which registers a function to be called when the action occurs).
using namespace vex;
// A global instance of vex::brain used for printing to the V5 brain screen
vex::brain Brain;
// define your global instances of motors and other devices here
vex::controller Controller;
vex::pneumatics Pn1(Brain.ThreeWirePort.A);
void
changePneumatics() {
Pn1.set( !Pn1.value() );
}
int main() {
Controller.ButtonA.pressed( changePneumatics );
while(1) {
// Allow other tasks to run
this_thread::sleep_for(10);
}
}
we can read current state of the pneumatics using value() method, then just negate and send back using set.
A normal double acting solenoid does that …