Thread: Boolean Help?
View Single Post
  #4   Spotlight this post!  
Unread 12-01-2015, 01:05
Team118Joseph's Avatar
Team118Joseph Team118Joseph is offline
The guy that did the lighting
AKA: Joseph Foster
FRC #0118 (Robonauts)
Team Role: Alumni
 
Join Date: Jan 2014
Rookie Year: 2013
Location: League City
Posts: 61
Team118Joseph will become famous soon enoughTeam118Joseph will become famous soon enough
Re: Boolean Help?

So he wants it to toggle? If so you will need 2 bools. One will store the current mode state and the other will store the last state of the button. If the button is true, it will check the the last state of the button. If the last state is false, change the state of the mode.

Here is an example in C++
Code:
//this code is in the class header
bool pressed;
bool value;

//this code is in the initializer
pressed = false;//saves the button press
value = false;//what ever is being toggled


//this code is in the periodic thread
if(joystick->GetRawButton(1))//gets the button value and checks if it is true
{
	if(pressed == false)//Checks if the last button state was false
        {
		value = !value; //flips the value
	}
	pressed = true;//saves the buttons state
}
else//if the button is not pressed
{
	pressed = false;//saves the buttons state
}
I know its not LabView but the concept should be the same.
__________________
FRC Countdown Website: http://frccountdown.hosthorde.net/
FRC Countdowns App: https://play.google.com/store/apps/d...h.frccountdown

Last edited by Team118Joseph : 12-01-2015 at 01:16. Reason: added comments to the code
Reply With Quote