Switching between multiple modes in an arduino uno

I need to make an arduino program that allows me to switch between 3 different tasks with the help of only one push button.

It should go back to Task 1 once we cross Task 3 by pushing the switch

(eg. Task 1: Read input from LDR Task 2: Glow the red LED Task 3: Display some text)

I have tried a lot but am not getting how to do it. Also the switch has to be debounced to prevent any errors but only through software, not hardware debounce.

How do I solve this entire problem?

The switch I am using is LOW when pressed down and HIGH in normal state.

Always show us your current sketch.

Use </> icon to attach you code.

Also, show us a good image of your wiring and a copy of your schematic.


Make 3 [u]while-loops[/u] inside your main loop. Stay in the current while-loop while the button is not pressed. When the button is pressed, you quit the current loop and go-on to the next one. And of course, when you exit the last while-loop, you'll automatically loop-back to the top of your main loop and the 1st while-loop will re-start.

alternatively, you could write a function for each of these functions, and again inside each function, stay in a loop waiting for button-press before you exit that function.

Also the switch has to be debounced

[u]Debounce Example[/u].

I would start out by first getting you 'push button' system working.

ie: a push button counter system.

press button - output 'task 1' press button again - output 'task 2' press button again - output 'task 3' press button again - (checking your threshold/limiter as we have reached '3') reset counter and - output 'task 1' (again)

Once you have that system working...

you can insert the functions/events you want to happen at each 'task cycle'