Hello, I am pretty new to coding but I tried to create a code to spin the intake once the L1 button is pressed once, and to stop the intake when either L1 or L2 is pressed afterwards. I tested it on the robot and it works a few times but after that it glitches and our intake won’t stop. I have my code down below, hope someone can help with this!
The pressing()
method continues to return true while the button is held, meaning your intake will toggle on and off very rapidly while the button is still pressed. You need some form of debouncing, like this:
bool button_was_pressed = false;
while (true)
{
if (Controller1.ButtonL1.pressing() != button_was_pressed)
{
// put code here that you only what to run when the state of the button changes
button_was_pressed = Controller1.ButtonL1.pressing();
}
}
Yes, after some more research and asking more experienced programmers I figured I should use some Boolean to define that it is pressed and that worked. Thanks though!