Java: Requiring a button press for a certain amount of time to unlock a function

We have an action on the robot that we would like to protect from accidental activation.

As a result, we want our operator to have to press and hold two buttons for X amount of time for this option to become available for the driver.

I have not found anything baked into WPILib to do this, and ‘timing’ events is also something we haven’t done before in Java since this is our first year using it.

What is the best practice / easiest way to make this happen?

My initial thought was to write the code in robot container, checking for the button press and starting a timer. When the timer passes, I can then set a boolean that unlocks the driver trigger command.

Assuming you’re using command-based,
You can do a().and(b()).debounce(X) to have a trigger that returns true when A and B have been simultaneously pressed for X seconds, and returns false immediately on release of either.

5 Likes

Yep, use a debounce here

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.