Author Options:

arduino button question? Answered

Hey guys I have an arduino question.
I want to run both servo sweep and servo knob at the same time But be controlled by a button. 
Like servo swep starts up, i mash a button, then servo knob comes on and i can manually control the servo.
then push a button (either the same or another) and servo sweep comes back.
This is for arduino uno r3.

Please advise



5 years ago

Use a variable to track the number of times the button has been pressed. You void loop will consist of checking if the button has been pressed or not. It will also check the state of the tracking variable. If the tracking variable equals 1 than it will send you down to a void that contains the code needed to sweep the serveo. If it equals 2 than it goes to a void where you use a pot to control the servo.


Answer 5 years ago

do you have an example of multiple void loops? i think i almost got it figured out its just not doing exactly what i want.


Answer 5 years ago

Check out my arduino simon says game or total recall game.



In the Arduino Simon Says code you will see towards the end of the void loop(0 it has the command input() which directs the code to the void input(). WHen the code is done with the void input() section it will return to the void loop() again. Unless of course it sees the user has failed. It will then send the code to the void fail() section which tells teh user they lost and restarts the game.