View Single Post
  #4   Spotlight this post!  
Unread 23-01-2013, 22:01
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
Re: Toggling Buttons in Java

Using whileHeld() would be an equivalent approach than making whenPressed() turn it on and whenReleased() turn it off. To make it toggle you need a command to somehow change the shooter's state based on a current state. I expect your shooter has some setRunning() and isRunning() (the methods might be different -- the important part is being able to tell whether or not the shooter is running). The logic you want (probably in initialize()) is this:
Code:
if(shooter is shooting) {
    turn shooter off;
} else {
    turn shooter on;
}
If your shooter is a PIDSubsystem, you can do something like this:
Code:
if(shooter.getSetpoint() != 0) {
    shooter.setSetpoint(shooterSpeed);
} else {
    shooter.setSetpoint(0);
}
__________________
I code stuff.
Reply With Quote