As stated in the subject matter, i have trouble with knowing how to have ONE pushbutton to do several things every time it is pressed.
Let's me use an example:
I have ONE pushbutton. First time it is pressed = action 1 happens, next time it is pressed = action 2 happens, etc.
Let's take my project:
I have an automatic drawer that i want to open and close. I have a H-bridge, which is used to run a 12V motor, which switches the direction, which opens and closes the drawer.
So let's get back to the example
Action 1 = Opens the drawer (runs motor, and stops at a given time, until next button press)
Action 2 = Closes the drawer (switches motor direction, and stops when drawer is closed)
I have an idea of this being in a loop, where you can state the amounts of button presses. For instance:
Int buttonPress = 0;
Then maybe have an if/else sentence, which controls the actions?
if (buttonPress==1) //Action 1
- Then does something here
else (do nothing)
And so on.
Hope you understand what i am getting at here. If not, please let me know!