I am creating a UI with an OLED, and I need the display to change when I push a button, and stay changed without my having to hold the button down. Currently, I am using a while loop as follows:
while (menuCount1 == 4 && clkenter == 0) {
I have my digital reads here for my buttons as well...
As soon as I let go of the button though, the loop stops (as it should), but what I need it to do is keep looping until I press the back button. So keep looping until an If command stops the loop. It works great if I don't read the buttons being pressed in the while loop, and just create an if --> break statement to get out of it, but I need to be able to read all of my buttons for the rest of the UI. Any ideas? Thanks so much everyone!
It's easy enough to do from first principles without resorting to a library, by following the technique of the state change detect tutorial, and toggle a boolean (as IoT_hobbyist did) each time there's a new press.
Side note: I think it's more common to use ! to mean not, rather then ~, so:
PS, since the nature of loop() is to loop, you probably could use if() rather than while() but without you posting a complete sketch it's difficult to give definitive advice.
twinkleyan:
PS, since the nature of loop() is to loop, you probably could use if() rather than while() but without you posting a complete sketch it's difficult to give definitive advice.
I'm using a OLED, so when I tried "If", it just flickered the display, but the boolean "while" command worked great. I just used displayed = !displayed and that did the trick. Thanks all!!