1#include <ItemIntRange.h>
2#include <ItemList.h>
3#include <ItemToggle.h>
4#include <LcdMenu.h>
5#include <MenuScreen.h>
6#include <SimpleRotary.h>
7#include <display/LiquidCrystal_I2CAdapter.h>
8#include <input/SimpleRotaryAdapter.h>
9#include <renderer/CharacterDisplayRenderer.h>
10
11#define LCD_ROWS 2
12#define LCD_COLS 16
13
14// Declare the callbacks
15void callback(int pos);
16void colorsCallback(uint8_t pos);
17void toggleBacklight(bool isOn);
18
19String colors[] = {"Red", "Green", "Blue", "Orange", "Aqua", "Yellow", "Purple", "Pink"};
20
21// clang-format off
22MENU_SCREEN(mainScreen, mainItems,
23 ITEM_BASIC("Connect to WiFi"),
24 ITEM_STRING_LIST("Color", colors, 8, colorsCallback),
25 ITEM_BASIC("Blink SOS"),
26 ITEM_INT_RANGE("Dist", 0, 50, 0, callback, "%dm"),
27 ITEM_TOGGLE("Backlight", toggleBacklight),
28 ITEM_BASIC("Blink random"));
29// clang-format on
30
31LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS);
32LiquidCrystal_I2CAdapter lcdAdapter(&lcd);
33CharacterDisplayRenderer renderer(&lcdAdapter, LCD_COLS, LCD_ROWS);
34LcdMenu menu(renderer);
35SimpleRotary encoder(2, 3, 4);
36SimpleRotaryAdapter rotaryInput(&menu, &encoder);
37
38void setup() {
39 Serial.begin(9600);
40 renderer.begin();
41 menu.setScreen(mainScreen);
42}
43
44void loop() { rotaryInput.observe(); }
45
46// Define the callbacks
47void toggleBacklight(bool isOn) {
48 lcdAdapter.setBacklight(isOn);
49}
50
51void callback(int pos) {
52 Serial.println(pos);
53}
54
55void colorsCallback(uint8_t pos) {
56 Serial.println(colors[pos]);
57}