#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// I2C adresini belirtin (genellikle 0x27 veya 0x3F)
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Buton pinleri
const int buttonPin1 = 7; // Seçim yapma butonu
const int buttonPin2 = 8; // Onaylama butonu
int buttonState1 = 0;
int buttonState2 = 0;
int menuIndex = 0;
const int menuItems = 3;
void setup() {
lcd.init();
lcd.backlight();
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
lcd.setCursor(0, 0);
lcd.print("Menu:");
updateMenu();
}
void loop() {
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
// Buton 1'e basıldıysa (menu değiştirme)
if (buttonState1 == LOW) {
menuIndex = (menuIndex + 1) % menuItems;
updateMenu();
delay(200); // Değişim hızını kontrol etmek için
}
// Buton 2'ye basıldıysa (seçim onaylama)
if (buttonState2 == LOW) {
lcd.setCursor(0, 1);
lcd.print("Selected: ");
lcd.print(menuIndex + 1);
delay(200);
}
}
void updateMenu() {
lcd.setCursor(0, 1);
switch (menuIndex) {
case 0:
lcd.print("1. Option 1 ");
break;
case 1:
lcd.print("2. Option 2 ");
break;
case 2:
lcd.print("3. Option 3 ");
break;
}
}