ButtonAdapter

 1#include <Button.h>
 2#include <ItemToggle.h>
 3#include <LcdMenu.h>
 4#include <MenuScreen.h>
 5#include <display/LiquidCrystal_I2CAdapter.h>
 6#include <input/ButtonAdapter.h>
 7#include <renderer/CharacterDisplayRenderer.h>
 8
 9#define LCD_ROWS 2
10#define LCD_COLS 16
11
12// Declare the call back function
13void toggleBacklight(bool isOn);
14
15// clang-format off
16MENU_SCREEN(mainScreen, mainItems,
17    ITEM_BASIC("Start service"),
18    ITEM_BASIC("Connect to WiFi"),
19    ITEM_TOGGLE("Backlight", toggleBacklight),
20    ITEM_BASIC("Blink SOS"),
21    ITEM_BASIC("Blink random"));
22// clang-format on
23
24LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS);
25LiquidCrystal_I2CAdapter lcdAdapter(&lcd);
26CharacterDisplayRenderer renderer(&lcdAdapter, LCD_COLS, LCD_ROWS);
27LcdMenu menu(renderer);
28Button upBtn(5);
29ButtonAdapter upBtnA(&menu, &upBtn, UP);
30Button downBtn(6);
31ButtonAdapter downBtnA(&menu, &downBtn, DOWN);
32Button enterBtn(7);
33ButtonAdapter enterBtnA(&menu, &enterBtn, ENTER);
34
35void setup() {
36    upBtn.begin();
37    downBtn.begin();
38    enterBtn.begin();
39    renderer.begin();
40    Serial.begin(9600);
41    menu.setScreen(mainScreen);
42}
43
44void loop() {
45    upBtnA.observe();
46    downBtnA.observe();
47    enterBtnA.observe();
48}
49/**
50 * Define callback
51 */
52void toggleBacklight(bool isOn) { lcdAdapter.setBacklight(isOn); }