#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
// === KONFIGURASI LCD (Alamat I2C bisa 0x27 atau 0x3F) ===
LiquidCrystal_I2C lcd(0x27, 16, 2);
// === KONFIGURASI KEYPAD 4x4 ===
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {13, 12, 14, 27}; // Sesuaikan dengan pin ESP32
byte colPins[COLS] = {26, 25, 33, 32};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
// === PASSWORD YANG DIGUNAKAN (NIM) ===
String inputPassword = "";
String storedPassword = "23024088"; // Ganti dengan NIM yang diinginkan
void setup() {
Serial.begin(115200);
// Inisialisasi LCD
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Masukkan NIM:");
}
void loop() {
char key = keypad.getKey();
if (key) {
Serial.print(key);
if (key == '#') { // Jika tombol "#" ditekan, verifikasi password
lcd.clear();
lcd.setCursor(0, 0);
if (inputPassword == storedPassword) {
lcd.print("Akses Diterima");
Serial.println("Akses Diterima");
} else {
lcd.print("Salah! Coba Lagi");
Serial.println("Akses Ditolak");
}
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Masukkan NIM:");
inputPassword = ""; // Reset input password
} else if (key == '*') { // Jika "*" ditekan, hapus input
inputPassword = "";
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Masukkan NIM:");
} else { // Tambahkan karakter ke input password
if (inputPassword.length() < 8) { // Maksimal 8 digit NIM
inputPassword += key;
lcd.setCursor(0, 1);
lcd.print(inputPassword);
}
}
}
}