#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const byte col = 4;
const byte bar = 4;
char datakey[col][bar] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte colpin[col] = {9, 8, 7, 6};
byte barpin[bar] = {5, 4, 3, 2};
Keypad keypad = Keypad(makeKeymap(datakey), colpin, barpin, col, bar);
String pass = "";
const String benar = "1212";
void setup() {
lcd.init();
lcd.backlight();
lcd.print("Enter Password:");
lcd.setCursor(0, 1);
}
void loop() {
char key = keypad.getKey();
if (key) {
if (key == 'D') { // Cek password
lcd.clear();
lcd.print(pass == benar ? "Pass Benar!" : "Pass Salah!");
delay(2000); // Tahan hasil selama 2 detik
resetDisplay();
} else if (key == '#') { // Reset input
resetDisplay();
} else { // Input password
pass += key;
lcd.print('*');
}
}
}
void resetDisplay() {
pass = ""; // Reset password
lcd.clear();
lcd.print("Enter Password:");
lcd.setCursor(0, 1);
}