LiquidMenu Arduino Library

repository·master·Indexed 43 days ago

https://github.com/vasilkalchev/liquidmenu

An Arduino library that wraps LiquidCrystal to provide a structured, hierarchical way to create interactive menus on LCD displays. It abstracts UI development into a bottom-up hierarchy of LiquidLine, LiquidScreen, LiquidMenu, and LiquidSystem classes. Features include support for callback functions, PROGMEM for memory-constrained environments, I2C configuration, custom glyphs, and scrolling text.

Tokens
2.7K
Snippets
9
Records
18
Agent score
55%

What's inside LiquidMenu

  1. Use getter functions in LiquidScreen objects

    master
    In LiquidScreen objects, you can use getter functions instead of static variables for properties. This allows for dynamic property evaluation, where the value is calculated at the time it is accessed rather than being fixed at the time of object creation. This is useful for properties that depend on changing state or external conditions.
  2. How LiquidMenu classes are organized

    master

    LiquidMenu uses a hierarchical class structure to build menus:

    1. LiquidLine: Represents a single line of text or numbers on the LCD display.
    2. LiquidScreen: A collection of LiquidLine objects that are displayed together on one screen.
    3. LiquidMenu: A collection of LiquidScreen objects. This is the primary class used to control the menu (switching screens, selecting lines, etc.).
    4. LiquidSystem: Used to combine multiple LiquidMenu objects (e.g., a 'Main Menu' and a 'Settings Menu'). It provides the same public interface as LiquidMenu and allows you to browse screens within the currently active menu.
  3. Requirements for LiquidMenu

    master

    To use LiquidMenu, ensure you have the following:

    • An Arduino board or compatible microcontroller.
    • An LCD supported by the LiquidCrystal library (using Hitachi HD44780 or a compatible chipset).
    • The Arduino LiquidCrystal library (or a similar one) installed.
    • Input hardware such as push-buttons for navigation.
  4. Create a custom glyph menu using LiquidLine

    master

    This pattern demonstrates how to create a custom character (glyph) and embed it within a LiquidLine object to build a menu item that uses a specific symbol instead of standard text. This is useful for creating icon-based or highly stylized menu interfaces.

    // This example demonstrates how to create a custom character (glyph) 
    // and put it inside a LiquidLine object.
  5. Basic LiquidMenu usage example

    master

    This example demonstrates how to initialize an LCD, create lines and screens, and update the menu in the main loop.

    // ...
    
    // First we need to instantiate the LiquidCrystal object.
    LiquidCrystal lcd(LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7);
    
    // a variable that will be updated periodically somewhere in our code
    float temperature = 0.0f;
    
    // ----- WELCOME SCREEN -----
    // a line of one string literal
    LiquidLine lineHello(2, 0, "Hello world!");
    LiquidLine lineRight(7, 1, ">");
    
    // create a screen from the above lines
    LiquidScreen screenMain(lineHello, lineRight);
    // --------------------------
    
    // ----- STATUS SCREEN -----
    // a line of two string literals and a float variable
    LiquidLine lineTemp(0, 0, "Temp: ", temperature, "C");
    LiquidScreen screenStatus(lineTemp);
    // -------------------------
    
    // ----- MENU -----
    // create a menu from the screens
    LiquidMenu menu(lcd, screenMain, screenStatus);
    // -----------------
    
    void setup() {
        lcd.begin(16, 2);
        
        // ...
    }
    
    void loop() {
        temperature = readTemperature();
        menu.update(); // update the display to show the new information
        
        if (rightButton()) {
            menu.next_screen();
        }
        if (leftButton()) {
            menu.previous_screen();
        }
        
        // ...
    }
  6. Implement a scrolling menu in LiquidMenu

    master
    A scrolling menu allows you to display long text strings by scrolling the lines instead of truncating them. This is useful when menu item labels exceed the available width of the display. Additionally, this pattern can be used to customize the precision of numeric values by overwriting the default number of displayed decimal places in the menu items.
  7. Display strings from flash memory (PROGMEM) in LiquidMenu

    master

    In memory-constrained environments like Arduino, you can use the progmem_menu pattern to display menu items where the strings are stored in flash memory (PROGMEM) instead of RAM. This prevents large menu structures from consuming the limited SRAM available to your application.

    /* This example demonstrates how to display a string stored in flash memory. */