Hi everyone,
I am working on a Arduino project where the board needs to take different inputs from the user, that are provided thru external buttons of an additional board.
The issue that I have is that I actually don’t know how to code a user interface with different levels of menus and submenus. The idea that I came upon uses while instructions, but I’m not sure it is the most efficient, and I cannot find a thread that discusses that, even if I think this should be a quite common problem.
I will try to explain this with an example. Let’s imagine that I want to build a custom timer and stopwatch. First, I need to choose between the two modes (timer or stopwatch). Then, for the timer, I need the user to select hours, minutes and seconds. For the stopwatch no other action is needed (apart from starting it). I’m doing this using only four buttons (+,-,confirm,back). How can I build a piece of code that let me chose the mode and set this three parameters?
The approach I followed uses nested while cycles (set to true) to wait the button to be pressed. When one of the buttons is pressed, an if statement detects that, leading into another while-true loop, that waits for the following selection to be made and confirmed (for instance, if + is pressed I add one hour/minute/second, if - is pressed i subtract one hour, if confirm is pressed i proceed to the following step).
This hierarchy full of nested while cycles is what looks quite strange and inconvenient to me. It was ok initially, but now that the code has became bigger and bigger (1000+ lines) it is becoming messy, and also producing a lot of bugs.
To sum up, the basic question behind this post is: Is there a way to design a menu-like structure (like the settings of old Nokia phones, for instance) using simple Arduino coding? If so, how?
I would prefer not to post the real code because it’s a mess, but I could do it if needed. I still hope you understood the problem and I’m open to any kind of suggestion.
Thank you very much for your help.
Have a nice day.
Luca