Introducing the arduino-menusystem library that makes it easy to incorporate a menu system into an Arduino project.


The library is implemented according to the composite design pattern. When using this library you need to create Menu’s, MenuItem’s, and a single MenuSystem.

A Menu represents an item in the menu that contains other Menu’s and MenuItem’s. Use add_menu_item() and add_menu() to build its contents.
A MenuItem represents an action. When select() is called the MenuItem’s callback function is called.
The MenuSystem contains the core functions for interacting with the menu system: next(), prev(), select(), and back().


First create the various Menu’s, MenuItem’s, and MenuSystem at the top of your source file. You will also need to create a root Menu to hold the top- level menu items. The root item is never displayed.

1#include <MenuSystem.h>
3MenuSystem ms;
4Menu mm("");
5MenuItem mi_time("TIME");
6MenuItem mi_date("DATE");
7MenuItem mi_alarm("ALARM");
8Menu mu_disp("DISP");
9MenuItem mi_disp_brightness("BRTNS");

In your Setup() function, put the menu system together.

 1void setup()
 3  // Menus
 4  mm.add_item(&mi_time, &on_menu_set_time);
 5  mm.add_item(&mi_date, &on_menu_set_date);
 6  mm.add_item(&mi_alarm, &on_menu_set_alarm);
 7  mm.add_menu(&mu_disp);
 8  mu_disp.add_item(&mi_disp_brightness, &on_menu_set_brightness);
 9  ms.set_root_menu(&mm);

Define your callback functions (only one is shown here).

1void on_menu_set_alarm(MenuItem* pMenuItem)
3  // Set the alarm

And finally, interact with your menu system using the functions listed below. This will usually happen when responding to user input.; // select the current menuitem/menu
2ms.back(); // go back to the menu one level up; // go to the next item in the current menu
4ms.prev(); // go to the previous item in the current menu
5ms.get_current_menu_name(); // get the current menu name
6ms.get_num_menu_items(); // get the number of menu items in the current menu
7ms.get_cur_menu_item(); // get the current menu item number in the current menu


There are several examples in the examples folder in the repository.