I have an arduino mega with a LCD shield (from keyestudio KS2056). I am trying to create a menu with a submenu that would have addable and removable strings based on inputs from a RFID scanner(addable) and buttons(to remove selected strings). I am not so sure how I could possibly do this. Any assistance would be great.

2 Answers 2


I will skip the RFID part, that is unrelated to the menu.

What you can do is creating two variables:

int menuLevel1 = 0;
int menuLevel2 = 0;

Assuming you have 2 levels, if you have more levels consider an array.

Now you can print the screen based on the values of these two variables (use a switch statement for menuLevel1 which calls new functions, each with their own switch statement for menuLevel2.

Note there are more solutions, but this is a rather simple solution.

The RFID scanner just changes the values, so going to a different menu screen.

A slightly different solution is to not use numbers, but an enumeration (or one for the main level, and x for the second level etc). This can add up, so you can also use a single enum value (with one entry per possible menu page).

The last example looks like:

enum EMenuPage

enum EMenuPage _menuPage;

Displaying like:

switch (_menuPage)
case StartPage:
   // Fill LCD with start page

case …

And when an RFID messages comes in:

if (RFID... == Back)
  _menuPage = MainMenu;
else …

[State machines][1]. it's the general form of the solution provided by michael above. it's a big help on situations when the application have to answer to, or act on many states (e.g. a menu). the good part is you can draw them on a piece of paper , draw a graph, manage input/output and write a general routine to act in various states. the state names themsevles can be represented by an integer variable and represented better by enumeration. after that, there should be a routine to act based on the current state, and the input from current state to go to another state. in it's easiest form, it's just a if-else block. depsite the idea is the same as the bare variable solution provided in the other answers, ignoring state machine related techniques (e.g. just drawing state graphs down on a piece of paper) makes a big application unmanageable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.