#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
const int upButton = 2;
const int downButton = 4;
const int selectButton = 1;
const int backButton = 3;
const int buzzerPin = 5;
int menu = 1;
void setup() {
lcd.begin(16, 2);
pinMode(upButton, INPUT_PULLUP);
pinMode(downButton, INPUT_PULLUP);
pinMode(selectButton, INPUT_PULLUP);
pinMode(backButton, INPUT_PULLUP);
pinMode(buzzerPin, OUTPUT);
}
void buzz() {
tone(buzzerPin, 1000); // Set the buzzer to a frequency of 1000 Hz
delay(100); // Adjust the delay time to control the beep duration
noTone(buzzerPin); // Stop the buzzer
}
void handleBackButton() {
buzz(); // Beep for the "back" button
lcd.clear();
if (menu > 1) {
menu--;
} else {
menu = 10;
}
delay(200);
}
void loop() {
lcd.clear();
if (digitalRead(upButton) == LOW) {
if (menu > 1) {
menu--;
} else {
menu = 10;
}
delay(200);
buzz();
}
if (digitalRead(downButton) == LOW) {
if (menu < 10) {
menu++;
} else {
menu = 1;
}
delay(200);
buzz();
}
if (digitalRead(selectButton) == LOW) {
buzz(); // Beep for the "select" button
lcd.clear();
switch (menu) {
case 1:
item1();
break;
case 2:
item2();
break;
case 3:
item3();
break;
case 4:
item4();
break;
case 5:
item5();
break;
case 6:
item6();
break;
case 7:
item7();
break;
case 8:
item8();
break;
case 9:
item9();
break;
case 10:
item10();
break;
}
delay(2000);
while (digitalRead(backButton) != LOW) {}
delay(200);
lcd.clear();
menu = 1;
delay(200);
return;
}
if (digitalRead(backButton) == LOW) {
handleBackButton();
}
switch (menu) {
case 1:
lcd.print(">Item1");
lcd.setCursor(0, 1);
lcd.print(" Item2");
break;
case 2:
lcd.print(" Item1");
lcd.setCursor(0, 1);
lcd.print(">Item2");
break;
case 3:
lcd.print(">Item3");
lcd.setCursor(0, 1);
lcd.print(" Item4");
break;
case 4:
lcd.print(" Item3");
lcd.setCursor(0, 1);
lcd.print(">Item4");
break;
case 5:
lcd.print(">Item5");
lcd.setCursor(0, 1);
lcd.print(" Item6");
break;
case 6:
lcd.print(" Item5");
lcd.setCursor(0, 1);
lcd.print(">Item6");
break;
case 7:
lcd.print(">Item7");
lcd.setCursor(0, 1);
lcd.print(" Item8");
break;
case 8:
lcd.print(" Item7");
lcd.setCursor(0, 1);
lcd.print(">Item8");
break;
case 9:
lcd.print(">Item9");
lcd.setCursor(0, 1);
lcd.print(" Item10");
break;
case 10:
lcd.print(" Item9");
lcd.setCursor(0, 1);
lcd.print(">Item10");
}
delay(100);
}
void item1() {
// code for item1
lcd.setCursor(0, 1);
lcd.print("Item1");
}
void item2() {
// code for item2
lcd.setCursor(0, 1);
lcd.print("Item2");
}
void item3() {
// code for item3
lcd.setCursor(0, 1);
lcd.print("Item3");
}
void item4() {
// code for item4
lcd.setCursor(0, 1);
lcd.print("Item4");
}
void item5() {
// code for item5
lcd.setCursor(0, 1);
lcd.print("Item5");
}
void item6() {
// code for item6
lcd.setCursor(0, 1);
lcd.print("Item6");
}
void item7() {
// code for item7
lcd.setCursor(0, 1);
lcd.print("Item7");
}
void item8() {
// code for item8
lcd.setCursor(0, 1);
lcd.print("Item8");
}
void item9() {
// code for item9
lcd.setCursor(0, 1);
lcd.print("Item9");
}
void item10() {
// code for item10
lcd.setCursor(0, 1);
lcd.print("Item10");
}