0

What would be the best way to toggle two buttons off and on in C++?(with out using a timer)

My solution(with a timer): If(m_Joystick->GetRawButton(7) && m_Joystick->GetRawButton(8) && time->Get() == 0) { Open all valves; Time->start; } Else if(m_Joystick->GetRawButton(7) && m_Joystick->GetRawButton(8) && time->Get() <= 0.5) { Close all valves; Time->reset; }

16th May 2017, 11:49 PM
Liam Olenick
Liam Olenick - avatar
1 Antwort
0
I expect you are getting the real input from "joystick" (as your varible name says) and want to get rid off the timer to toggle a button or something similar. Lets say your want to toggle a LED on/off. I would toggle it using following code. bool ledLight = false;// LED is off if(m_Joystick->getRawButton(7) && m_Joystick->getRawButton(8)) { ledLight = (ledLight)? false:true;//toggle LED value } hope this helps.Thanks..
29th May 2017, 9:23 PM
Patel