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