chore: add example menu demo
This commit is contained in:
@@ -6,6 +6,14 @@
|
||||
Joystick joystick;
|
||||
Display display;
|
||||
|
||||
Item items[MENU_ITEM_COUNT] = {
|
||||
{"Feed", []() { Serial.println("Feeding..."); }},
|
||||
{"Play", []() { Serial.println("Playing..."); }},
|
||||
{"Sleep", []() { Serial.println("Sleeping..."); }},
|
||||
{"Clean", []() { Serial.println("Cleaning..."); }}
|
||||
};
|
||||
Menu menu(items);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
@@ -14,7 +22,19 @@ void setup() {
|
||||
|
||||
display.begin();
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
display.drawMenu(menu);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
JoystickDirection direction = joystick.getDirection();
|
||||
if (direction != JoystickDirection::CENTER) {
|
||||
menu.updateCurrentItem(direction);
|
||||
display.drawMenu(menu);
|
||||
}
|
||||
|
||||
if (joystick.isPressed()) {
|
||||
menu.execute();
|
||||
}
|
||||
|
||||
delay(250);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user