#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
String menuItems[] = {"Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6"};
int selectedMenuItem = 0;
int Page = 0;
const int buttonPin1 = 2; // button for moving up
const int buttonPin2 = 3; // button for moving down
const int buttonPin3 = 4; // button for selecting item
void setup() {
lcd.begin(20, 4);
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
pinMode(buttonPin3, INPUT_PULLUP);
Serial.begin(115200);
}
void displayMenu() {
//lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Select an Item:");
int x = 0;
for (int i = 0; i < 6; i++) {
x = i;
lcd.setCursor(0, i + 1);
if (selectedMenuItem == i) {
lcd.print(">");
} else {
lcd.print(" ");
}
lcd.print(menuItems[i]);
}
}
void handleInput() {
if (digitalRead(buttonPin1) == LOW) {
selectedMenuItem--;
if (selectedMenuItem < 0) {
selectedMenuItem = 5;
}
delay(250);
}
if (digitalRead(buttonPin2) == LOW) {
selectedMenuItem++;
if (selectedMenuItem > 5) {
selectedMenuItem = 0;
}
delay(250);
}
if (digitalRead(buttonPin3) == LOW) {
lcd.setCursor(10, 4);
lcd.print(selectedMenuItem);
}
}
void loop() {
displayMenu();
handleInput();
}