I am a newbie on Arduino but I already did the tutorials, so the basics are there, hopefully.
I have a couple of push buttons that execute code, like rotate servos, change LEDs, ...
Now I want to join them in one single project.
Before starting I would like to know the better way to "disable" a push button while the code is being executed.
I do not want to be possible to press again the same button while the code for that button is being executed, but I want to be able to press another button and execute another code.
xl97:
Just dont check the state (change) of that particular button then?
But I have to to be constantly checking for a button press to execute the code.
Sorry, it may be trivial but I do not understand.
UKHeliBob:
Make reading the button state dependant on a boolean. Change the state of the boolean to enable/disable reading the state of the button.
So, for example, in the code of the button press I insert an if statement checking "actionstarted == False" and then inside I update "actionstarted = True". Then comes the stuff to be executed and in the end of the code I update again "actionstarted = False". Similar to debouncing using millis()
FilipeAlmeida:
So, for example, in the code of the button press I insert an if statement checking "actionstarted == False" and then inside I update "actionstarted = True". Then comes the stuff to be executed and in the end of the code I update again "actionstarted = False". Similar to debouncing using millis()
Yes, that's the idea.
And when you're at it, look into the concept of "finite state machine" as that's what you're doing here. You put your machine into a different state based on button press and code execution stage.