View Single Post
  #6   Spotlight this post!  
Unread 16-10-2015, 16:00
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,574
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Help first time programmer

Quote:
Originally Posted by dwhite View Post
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...
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.

Last edited by GeeTwo : 16-10-2015 at 16:05.
Reply With Quote