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();
}
// ...
}