View Single Post
  #2   Spotlight this post!  
Unread 29-05-2012, 13:32
Mark McLeod's Avatar
Mark McLeod Mark McLeod is online now
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,753
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: Java Toggle Button

You need an interlock, something along the pseudo-code lines of:

Code:
boolean belt = false;
boolean toggle = true;
 
if (toggle && Button) {  // Only execute once per Button push
  toggle = false;  // Prevents this section of code from being called again until the Button is released and re-pressed
  if (belt) {  // Decide which way to set the motor this time through (or use this as a motor value instead)
    belt= false;
    conveyorMotor.set(1);
  } else {
    belt= true;
    conveyorMotor.set(0);
  }
} else if(Button == FALSE) { 
    toggle = true; // Button has been released, so this allows a re-press to activate the code above.
}
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 29-05-2012 at 13:54.
Reply With Quote