#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const byte ROWS = 4; //jumlah baris keypad
const byte COLS = 4; //jumlah kolom keypad
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {14, 12, 19, 18}; //R1, R2, R3, R4
byte colPins[COLS] = {5, 4, 2, 15}; //C1, C2, C3, C4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
const char *password = "3033";
char enteredPassword[5];
int passwordIndex = 0;
void setup() {
Serial.begin(115200);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Press :");
}
void loop() {
char key = keypad.getKey();
if (key) {
lcd.setCursor(6, 0); // Set kursor ke posisi setelah kata "Press"
lcd.print(key); // Tampilkan karakter yang ditekan
lcd.setCursor(passwordIndex, 1);
lcd.print('*');
enteredPassword[passwordIndex] = key;
passwordIndex++;
if (passwordIndex == 4) {
lcd.clear();
passwordIndex = 0;
if (strcmp(enteredPassword, password) == 0) {
lcd.print("Password correct!");
} else {
lcd.print("Invalid password!");
}
delay(2000);
lcd.clear();
lcd.print("Press");
memset(enteredPassword, 0, sizeof(enteredPassword));
}
}
}