Thread: Help !!!!
View Single Post
  #4   Spotlight this post!  
Unread 28-03-2012, 15:23
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: Help !!!!

Both toggle and cycle buttons are based on a button "press" instead of just being held down. To detect when a button is pressed:
Code:
// outside the "checking" loop
boolean prevState = false;

// inside checking loop; can be within continuous or periodic
boolean currentState = joy.getRawButton(DESIRED_BUTTON);
if(currentState && !prevState) {
    // Button DESIRED_BUTTON is newly pressed
    // Do stuff here
}
prevState = currentState;
To do a toggle, have an extra boolean (e.g. tracking), then when the button is pressed:
Code:
tracking = !tracking;
To do a cycle, have an int (e.g. basketChoice) and do this on button pressed:
Code:
basketChoice = (basketChoice+1)%NUM_CHOICES;
Reply With Quote