1#include <ItemFloatRange.h>
2#include <ItemIntRange.h>
3#include <LcdMenu.h>
4#include <MenuScreen.h>
5#include <display/LiquidCrystal_I2CAdapter.h>
6#include <input/KeyboardAdapter.h>
7#include <renderer/CharacterDisplayRenderer.h>
8
9#define LCD_ROWS 2
10#define LCD_COLS 16
11
12// Declare the callbacks
13void callbackInt(int value);
14void callbackFloat(float value);
15
16// Initialize the main menu items
17// clang-format off
18MENU_SCREEN(mainScreen, mainItems,
19 ITEM_BASIC("Con"),
20 ITEM_INT_RANGE("Dist", 100, 200, 100, callbackInt, "%02dm"),
21 ITEM_FLOAT_RANGE("Curr", -1.0f, 1.0f, -1.0f, callbackFloat, "%.2fmA", 0.01f),
22 ITEM_BASIC("Blink SOS"),
23 ITEM_BASIC("Blink random"));
24// clang-format on
25
26// Construct the LcdMenu
27LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS);
28CharacterDisplayRenderer renderer(new LiquidCrystal_I2CAdapter(&lcd), LCD_COLS, LCD_ROWS);
29LcdMenu menu(renderer);
30KeyboardAdapter keyboard(&menu, &Serial);
31
32void setup() {
33 Serial.begin(9600);
34 // Initialize LcdMenu with the menu items
35 renderer.begin();
36 menu.setScreen(mainScreen);
37}
38
39void loop() {
40 keyboard.observe();
41}
42
43void callbackInt(int value) {
44 // do something with the integer value
45 Serial.println(value);
46}
47
48void callbackFloat(float value) {
49 // do something with the float value
50 Serial.println(value);
51}