1#include <ItemWidget.h>
2#include <LcdMenu.h>
3#include <MenuScreen.h>
4#include <display/LiquidCrystalAdapter.h>
5#include <input/AnalogButtonAdapter.h>
6#include <renderer/CharacterDisplayRenderer.h>
7#include <widget/WidgetList.h>
8
9#define LCD_ROWS 2
10#define LCD_COLS 16
11
12std::vector<const char*> colors = {"Red", "Green", "Blue", "Orange", "Aqua", "Yellow", "Purple", "Pink"};
13std::vector<uint8_t> nums = {5, 7, 9, 12, 32};
14
15// Initialize the main menu items
16// clang-format off
17MENU_SCREEN(mainScreen, mainItems,
18 ITEM_BASIC("Keypad demo"),
19 ITEM_WIDGET(
20 "Color",
21 [](const uint8_t color) { Serial.println(colors[color]); },
22 WIDGET_LIST(colors, 0, "%s", 0, true)),
23 ITEM_WIDGET(
24 "Num",
25 [](const uint8_t num) { Serial.println(nums[num]); },
26 WIDGET_LIST(nums, 0, "%d", 0, true)),
27 ITEM_BASIC("Example"));
28// clang-format on
29
30// Construct the LcdMenu
31LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
32CharacterDisplayRenderer renderer(new LiquidCrystalAdapter(&lcd, LCD_COLS, LCD_ROWS), LCD_COLS, LCD_ROWS);
33LcdMenu menu(renderer);
34
35AnalogButtonAdapter ButtonBackSpace(&menu, A0, 20, BACKSPACE);
36AnalogButtonAdapter ButtonUp(&menu, A0, 100, 20, UP);
37AnalogButtonAdapter ButtonDown(&menu, A0, 250, 20, DOWN);
38AnalogButtonAdapter ButtonBack(&menu, A0, 400, 20, BACK);
39AnalogButtonAdapter ButtonEnter(&menu, A0, 640, 20, ENTER);
40
41void setup() {
42 Serial.begin(9600);
43 renderer.begin();
44 menu.setScreen(mainScreen);
45}
46
47void loop() {
48 ButtonBackSpace.observe();
49 ButtonUp.observe();
50 ButtonDown.observe();
51 ButtonBack.observe();
52 ButtonEnter.observe();
53}