I still see one issue with notmattlythgoe's solution: since the buttonPressed is
always equal to the state of the button, the modes will only be switched while the button is being held down and return to the default mode when the button is released.
You could then do something like this:
Code:
public void teleopPeriodic() {
boolean buttonPressed = false;
if (stick.getRawButton(3)) {
buttonPressed = !buttonPressed;
}
if (buttonPressed) {
drive1.arcadeDrive(stick);
} else {
drive.arcadeDrive(stick);
}
}
However, then the modes would keep switching as long is the button is held. Really what you care about is when the button state changes from false to true. You can keep track of this with two booleans, one for the old state and one for the new.
So what you actually want is this:
Code:
public void teleopInit(){
oldButtonState = false;
newButtonState = false;
}
public void teleopPeriodic() {
newButtonState = stick.getRawButton(3);
if (newButtonState && !oldButtonState) {
drive1.arcadeDrive(stick);
} else {
drive.arcadeDrive(stick);
}
oldButtonState = newButtonState;
}
Also add declarations for oldButtonState and newButtonState as booleans with the rest of your declarations.
There might be a more elegant solution, but hopefully that works.
Hope that helps!
