chore: add example menu demo
This commit is contained in:
@@ -6,6 +6,14 @@
|
|||||||
Joystick joystick;
|
Joystick joystick;
|
||||||
Display display;
|
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() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
while (!Serial) {
|
while (!Serial) {
|
||||||
@@ -14,7 +22,19 @@ void setup() {
|
|||||||
|
|
||||||
display.begin();
|
display.begin();
|
||||||
pinMode(LED_BUILTIN, OUTPUT);
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
|
display.drawMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
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