View Single Post
  #6   Spotlight this post!  
Unread 08-06-2012, 16:04
daniel_dsouza daniel_dsouza is offline
does what needs to be done.
FRC #2449 (Out of Orbit Robotics)
Team Role: Alumni
 
Join Date: May 2011
Rookie Year: 2011
Location: Chandler, AZ
Posts: 231
daniel_dsouza has a spectacular aura aboutdaniel_dsouza has a spectacular aura about
Re: Java Toggle Button

You could do this in 2 parts:

Code:
//In the code that iterates:
     if (getButton() == true) state = true; //if button is pressed, var goes to true
     else if(state && !getButton()) { //if button was pressed, but isn't now
            belt.toggle();
            state= false; //says button was not pressed for next instance
     }

//In your belt class:
     public void toggle() {
          if (motor.get() == 1) motor.set(0); //this could be simpler depending on your application
          else if (motor.get == 0) motor.set(1);
     }
This is similar to some sensitivity code we wrote last year:
Code:
if (GAMEPAD_R1) shiftUp = true;
else if(GAMEPAD_R2) shiftDown = true;
else if(shiftUp && !GAMEPAD_R1) { //only allows shift if button has been pushed, then released, to allow one shift per click.
    drivetrain.shift(true);
    shiftUp = false;
}
else if(shiftDown && !GAMEPAD_R2){
    drivetrain.shift(false);
    shiftDown = false;
}
Reply With Quote