Quote:
Originally Posted by Ether
Two different ways to turn a momentary-contact button into a toggle:
Code:
if ( buttonIsPressed() ) // test button state
{
if (!buttonWasPressed) toggle(); // toggle if state changed from "not pressed" to "pressed"
buttonWasPressed=1; // remember button state for next iteration
}
else buttonWasPressed=0; // remember button state for next iteration
I like this one better:
Code:
IsPressed = buttonIsPressed(); // get new button state
if (IsPressed && !WasPressed) toggle(); // toggle if state changed from "not pressed" to "pressed"
WasPressed=IsPressed; // remember button state for next iteration
|
What language is that? Buttons have no isPressed wasPressed etc