Quote:
Originally Posted by dwhite
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;
}
|
This will drive in mode "drive1" for one cycle each time the button is pressed. You also need another (Boolean) variable, perhaps driveMode. Inside the if above, toggle the driveMode variable. Then, outside the if, base drive mode on the variable:
Code:
public void teleopInit(){
oldButtonState = false;
newButtonState = false;
driveMode = false;
}
public void teleopPeriodic() {
newButtonState = stick.getRawButton(3);
if (newButtonState && !oldButtonState) {
driveMode = !driveMode;
}
oldButtonState = newButtonState;
if (driveMode) {
drive1.arcadeDrive(stick);
} else {
drive.arcadeDrive(stick);
}
}
an enum would be even neater...