#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define bUP 7
#define bMN 6 // Tombol setting sesuaikan dengan PIN di arduino anda mana klo ini terhubung dengan PIN 3 Digital
#define bDN 5 // Tombol OK sesuaikan dengan PIN di arduino anda mana klo ini terhubung dengan PIN 5 Digital
//#define bEX 4 //tombol setting sesuaikan dengan PIN di arduino anda mana klo ini terhubung dengan PIN 4 Digital
void setup () {
lcd.begin(16, 2);
lcd.backlight();
pinMode(bMN, INPUT_PULLUP); // Mode Pin Sebagai Input dengan Pull Up Internal
pinMode(bUP, INPUT_PULLUP); // Mode Pin Sebagai Input dengan Pull Up Internal
pinMode(bDN, INPUT_PULLUP);
//pinMode(bEX, INPUT_PULLUP);
}
void loop()
{
lcd.setCursor(0, 0);
lcd.print(" tombol biru");
lcd.setCursor(0, 1);
lcd.print(" untuk masuk set");
if (digitalRead(bMN) == LOW) {
while (digitalRead(bMN) == LOW); // tunggu tombol dilepas
lcd.clear();
menuSetting();
}
}
void menuSetting() {
int posisi = 0; // 0 = baris atas, 1 = baris bawah
const char* menu[2] = {"SETTING WAKTU", "SETTING TAHUN"};
while (1) {
// Tampilkan menu
lcd.setCursor(0, 0);
lcd.print((posisi == 0) ? "> " : " ");
lcd.print(menu[0]);
lcd.print(" "); // bersihkan sisa karakter
lcd.setCursor(0, 1);
lcd.print((posisi == 1) ? "> " : " ");
lcd.print(menu[1]);
lcd.print(" ");
// Tombol turun
if (digitalRead(bDN) == LOW) {
while (digitalRead(bDN) == LOW);
posisi++;
if (posisi > 1)
posisi = 0;
}
// Tombol naik
if (digitalRead(bUP) == LOW) {
while (digitalRead(bUP) == LOW);
posisi--;
if (posisi < 0) posisi = 1;
}
// Tombol pilih
if (digitalRead(bMN) == LOW) {
while (digitalRead(bMN) == LOW);
lcd.clear();
lcd.print(" --SAVE-- ");
lcd.print(menu[posisi]);
delay(1500);
break; // keluar dari menu setelah memilih
}
delay(100); // debounce
}
lcd.clear();
}