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
24std::vector<const char*> colors = {"Red", "Green", "Blue", "Orange", "Aqua", "Yellow", "Purple", "Pink"};
25
26// clang-format off
27MENU_SCREEN(mainScreen, mainItems,
28 ITEM_INPUT_CHARSET("User", (const char*)"ABCDEFGHIJKLMNOPQRSTUVWXYZ", inputCallback),
29 ITEM_WIDGET(
30 "Color",
31 [](const uint8_t color) { Serial.println(colors[color]); },
32 WIDGET_LIST(colors, 0, "%s")),
33 ITEM_TOGGLE("Backlight", toggleBacklight),
34 ITEM_BASIC("Placeholder 1"),
35 ITEM_BASIC("Placeholder 2"));
36// clang-format on
37
38LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS);
39LiquidCrystal_I2CAdapter lcdAdapter(&lcd);
40CharacterDisplayRenderer renderer(&lcdAdapter, LCD_COLS, LCD_ROWS);
41LcdMenu menu(renderer);
42SimpleRotary encoder(2, 3, 4);
43SimpleRotaryAdapter rotaryInput(&menu, &encoder); // Rotary input adapter
44Button backspaceBtn(11);
45ButtonAdapter backspaceBtnA(&menu, &backspaceBtn, BACKSPACE); // Push button for backspace
46
47void setup() {
48 backspaceBtn.begin();
49 renderer.begin();
50 Serial.begin(9600);
51 menu.setScreen(mainScreen);
52}
53
54void loop() {
55 rotaryInput.observe();
56 backspaceBtnA.observe();
57}
58
59// Define the callbacks
60void toggleBacklight(bool isOn) {
61 lcdAdapter.setBacklight(isOn);
62}
63
64void inputCallback(char* value) {
65 Serial.println(value);
66}