View Single Post
  #4   Spotlight this post!  
Unread 16-10-2015, 15:28
dwhite's Avatar
dwhite dwhite is offline
I can SERTainly make puns.
AKA: Dani White
FRC #2521 (SERT)
Team Role: Programmer
 
Join Date: Jul 2015
Rookie Year: 2015
Location: Eugene, OR
Posts: 3
dwhite is an unknown quantity at this point
Re: Help first time programmer

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!
Reply With Quote