List

 1#include <ItemList.h>
 2#include <LcdMenu.h>
 3#include <MenuScreen.h>
 4#include <display/LiquidCrystal_I2CAdapter.h>
 5#include <input/KeyboardAdapter.h>
 6#include <renderer/CharacterDisplayRenderer.h>
 7
 8#define LCD_ROWS 2
 9#define LCD_COLS 16
10
11// Declare the callbacks
12void colorsCallback(uint8_t pos);
13void numsCallback(uint8_t pos);
14
15// Declare the array
16extern String colors[];
17// Initialize the array
18String colors[] = {"Red", "Green", "Blue", "Orange", "Aqua", "Yellow", "Purple", "Pink"};
19
20// Declare the array
21extern String nums[];
22// Initialize the array
23String nums[] = {"5", "7", "9", "12", "32"};
24
25// Initialize the main menu items
26// clang-format off
27MENU_SCREEN(mainScreen, mainItems,
28    ITEM_BASIC("List demo"),
29    ITEM_STRING_LIST("Col", colors, 8, colorsCallback),
30    ITEM_STRING_LIST("Num", nums, 5, numsCallback),
31    ITEM_BASIC("Example"));
32// clang-format on
33
34// Construct the LcdMenu
35LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS);
36CharacterDisplayRenderer renderer(new LiquidCrystal_I2CAdapter(&lcd), LCD_COLS, LCD_ROWS);
37LcdMenu menu(renderer);
38KeyboardAdapter keyboard(&menu, &Serial);
39
40void setup() {
41    Serial.begin(9600);
42    renderer.begin();
43    menu.setScreen(mainScreen);
44}
45
46void loop() {
47    keyboard.observe();
48}
49
50// Define the callbacks
51void colorsCallback(uint8_t pos) {
52    // do something with the index
53    Serial.println(colors[pos]);
54}
55
56void numsCallback(uint8_t pos) {
57    // do something with the index
58    Serial.println(nums[pos]);
59}