1// Disable double press detection
2#define DOUBLE_PRESS_THRESHOLD 0
3
4#include <Button.h>
5#include <ItemInputCharset.h>
6#include <ItemToggle.h>
7#include <ItemWidget.h>
8#include <LcdMenu.h>
9#include <MenuScreen.h>
10#include <SimpleRotary.h>
11#include <display/LiquidCrystal_I2CAdapter.h>
12#include <input/ButtonAdapter.h>
13#include <input/SimpleRotaryAdapter.h>
14#include <renderer/CharacterDisplayRenderer.h>
15#include <widget/WidgetList.h>
16
17#define LCD_ROWS 2
18#define LCD_COLS 16
19
20// Declare the callbacks
21void toggleBacklight(bool isOn);
22void inputCallback(char* value);
23
24static const char* colors[] = {"Red", "Green", "Blue", "Orange", "Aqua", "Yellow", "Purple", "Pink"};
25static const uint8_t COLORS_COUNT = sizeof(colors) / sizeof(colors[0]);
26
27// clang-format off
28MENU_SCREEN(mainScreen, mainItems,
29 ITEM_INPUT_CHARSET("User", (const char*)"ABCDEFGHIJKLMNOPQRSTUVWXYZ", inputCallback),
30 ITEM_WIDGET(
31 "Color",
32 [](const char* color) { Serial.println(color); },
33 WIDGET_LIST(colors, COLORS_COUNT, 0, "%s")),
34 ITEM_TOGGLE("Backlight", toggleBacklight),
35 ITEM_BASIC("Placeholder 1"),
36 ITEM_BASIC("Placeholder 2"));
37// clang-format on
38
39LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS);
40LiquidCrystal_I2CAdapter lcdAdapter(&lcd);
41CharacterDisplayRenderer renderer(&lcdAdapter, LCD_COLS, LCD_ROWS);
42LcdMenu menu(renderer);
43SimpleRotary encoder(2, 3, 4);
44SimpleRotaryAdapter rotaryInput(&menu, &encoder); // Rotary input adapter
45Button backspaceBtn(11);
46ButtonAdapter backspaceBtnA(&menu, &backspaceBtn, BACKSPACE); // Push button for backspace
47
48void setup() {
49 backspaceBtn.begin();
50 renderer.begin();
51 Serial.begin(9600);
52 menu.setScreen(mainScreen);
53}
54
55void loop() {
56 rotaryInput.observe();
57 backspaceBtnA.observe();
58}
59
60// Define the callbacks
61void toggleBacklight(bool isOn) {
62 lcdAdapter.setBacklight(isOn);
63}
64
65void inputCallback(char* value) {
66 Serial.println(value);
67}