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;