I made a button toggle for pneumatics in VEXcode, and translated it to PROS as I’m migrating to PROS. In theory, all of the methods line up. It works as intended on VEXcode. Yet instead of being a toggle on PROS, it’s like a normal button, where the piston extends while you’re holding the button and retracts when you let go. Any help would be appreciated. I compared documentation, pressing() & get_digital seem to do the same thing, so that’s why I’m confused. Thanks!
// To clarify the intended / expected outcome, what it does on VEXcode is I press ButtonB once and it toggles the pneumatics on, then press again to toggle them off. (So I’ m trying to replicate it on PROS, I tried multiple methods. That’s why I brought it here.)
VEXcode:
bool toggle = false;
bool latch = false;
if (toggle){
solenoid = true; // turns clamp solenoid on
}
else {
solenoid = false; // turns clamp solenoid off
}
if (controller1.ButtonB.pressing()) {
if(!latch){ // if latch false, toggle one time and set latch true
toggle = !toggle;
latch = true;
}
}
else {
latch = false; //once button is released then release the latch too
}
PROS:
bool b_button = master.get_digital(DIGITAL_B);
bool toggle = false;
bool latch = false;
if (toggle){
piston.set_value(true); // turns clamp solenoid on
}
else {
piston.set_value(false); // turns clamp solenoid off
}
if (b_button) {
if(!latch){ // if latch is false, flip toggle one time and set latch to true
toggle = !toggle;
latch = true;
}
}
else {
latch = false; //once button is released then release the latch too
}
static bool toggle { false }; //This static variable will keep state between loops or function calls
if(master.get_digital_new_press(DIGITAL_B)) {
piston.set(!toggle); //When false go to true and in reverse
toggle = !toggle //Flip the toggle to match piston state
}
I didn’t test this code, but it should give you a general idea.
Highly recommend using okapilib with pros. It was possible to reprogram our entire bot in only a day (which took weeks on raw pros). Plus it has a lot of shiny features.
definitely going to use okapi for odometry once I get this done, I looked at the docs and didn’t see any other methods for buttons in okapi, which is why I didn’t bother with it for now. thanks, I will test this right away
that code unfortunately didn’t work yields the same results as mine. i’m familiar with OOP. i dont see a difference in okapi’s methods versus PROS but i will try an okapi method just to be sure.
It’s been awhile since I’ve read or worked through code so I’m probably way off - but in VexCode it is 'ButtonB.pressing '; are you sure that the translated into Pros code is also ‘pressing’ vs ‘pressed’?
not 100% sure, but pressed is not what im looking for. PROS has get_digital and get_digital_new_press. i tested both and they dont work. its either that they’re not equivalent to pressing(), or something is wrong with my code. testing okapilib rn.
ButtonBase and by extension ControllerButton’s isPressed() works!! thanks for the suggestion to look into it sooner. i guess it’s just that the pros methods are not equivalent.
I did a search for Vex Pros toggle button and got a few hits - these 2 both seem to have a program very similar to the Pros one that you have above but with a few minor tweaks. I see you got a solution (GREAT!), but you might run a few tests with those tweaks just to see if you can determine how the methods link together better. If either of the ones below worked, they are so close to being what you had…