View Single Post
  #2   Spotlight this post!  
Unread 08-02-2015, 00:00
tomy tomy is offline
Registered User
FRC #3038 (I.C.E. Robotics)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Stacy, Minnesota
Posts: 494
tomy has a spectacular aura abouttomy has a spectacular aura about
Re: Help with toggle-button

My team does type of action for our dual acting solenoid.

Code:
bool isReady;
bool Piston;

isReady = true;
Piston = false; 


if (DriverJoyStick.GetTrigger() && isReady && !Piston){
		Piston = true;
		isReady = false;
} else if (DriverJoyStick.GetTrigger() && isReady && Piston {
		Piston = false;
		isReady = false;
} else if (!DriverJoyStick.GetTrigger()){
		isReady = true;
}
Where when you press the DriverJoystick Trigger and release it, it toggles the Boolean HalfSpeed. The Boolean you can set later in your code. We use it such as.

Code:
if(Piston){
	piston.Set(Relay::kForward);
} else if (!Piston){
	piston.Set(Relay::kReverse);
}
Reply With Quote