Arduino library for creating menus on LCD display "LiquidMenu"

Download the "LiquidMenu" Arduino library. To create a menu.

Arduino library for creating menus on LCD display "LiquidMenu"
Arduino library for creating menus on LCD display

The LiquidMenu library wraps the LiquidCrystal Arduino library with the ability to create menus. It simplifies the menu creation process by abstracting menu items into hierarchically organized classes.

Requirements

  • Arduino library LiquidCrystal or similar.
  • LCD display that supports LiquidCrystal (Hitachi HD44780 chipset or compatible).
  • Arduino board or compatible microcontroller.
  • Input device recommended (buttons, rotary encoder, etc.). For example, an expansion board with a display and buttons.

 

 Basic class hierarchy diagram

Complete class hierarchy diagram

Menu creation is all about structure. First, we have the variables / constants that go into the LiquidLine objects. The LiquidLine objects are then part of the LiquidScreen objects. The LiquidScreen objects are then part of the LiquidMenu object (s). And, optionally, LiquidMenu objects are part of the LiquidSystem object. This structure can be implemented when the object is created or later using public methods of the classes.

LiquidLine(byte column, byte row, A &variableA...);

// Accepts 0 to 4 LiquidLine objects.
LiquidScreen(LiquidLine &liquidLine1...);

// Accepts a reference to a LiquidCrystal object, 0 to 4 LiquidScreen objects, and
// screen number to be shown first.
LiquidMenu(LiquidCrystal &liquidCrystal, LiquidScreen &liquidScreen1..., byte startingScreen = 1);

// Accepts 0 to 4 LiquidMenu objects and the number of the menu that will be shown first.
LiquidSystem(LiquidMenu &liquidMenu1..., byte startingMenu = 1);

Menu navigation

Menu navigation is done from the LiquidMenu object or, if there are multiple menus, from the LiquidSystem object. Screens can be looped back and forth, or a specific screen can be specified by its object or number:

void LiquidMenu::next_screen();
void LiquidMenu::previous_screen();
bool LiquidMenu::change_screen(LiquidScreen &liquidScreen);

Focus and callback functions

Lines of text / numbers shown on the display can be interactive. Each line has callback functions attached to it (up to 8 by default). They are attached using a user-supplied number:

bool LiquidLine::attach_function(byte number, void (*function)(void));

To call a function attached to a row, the row must have focus (the row has been selected). To cycle through the lines shown on the screen, use the method:

void LiquidMenu::switch_focus(bool forward = true);

When a row is selected, one of the attached functions can be called with:

void LiquidMenu :: call_function (byte number);

number indicates which of the attached functions should be called.

example

// First, we need to create a LiquidCrystal object.
LiquidCrystal lcd(LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7);

// ----- Welcome screen -----
/// Create a string with one string literal.
LiquidLine welcome_line1(1, 0, "Hello Menu");

/// Creating a string with an integer variable.
byte oneTwoThree = 123;
LiquidLine welcome_line2(2, 1, oneTwoThree);

/// Screen formation from the above lines.
LiquidScreen welcome_screen(welcome_line1, welcome_line2);
// --------------------------

// ----- Screen 2 -----
LiquidLine some_line(0, 0, "Some line");
LiquidScreen some_screen(some_line);
// --------------------

// Now let's arrange the screens in the menu.
LiquidMenu my_menu(lcd, welcome_screen, some_screen);

void setup() {
    lcd.begin(16, 2);
    ...
}

void loop() {
    if (rightButton) {
        my_menu.next_screen();
    }
    if (leftButton) {
        my_menu.previous_screen();
    }
    if (somethingElse) {
        oneTwoThree++;
        my_menu.update;
    }
    ...
}


Find out about the update of this script first in our telegram channel: https://t.me/proweblabxyz