#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define PASSWORD "1234" // Correct password
LiquidCrystal_I2C lcd(0x27, 16, 2);
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};
byte colPins[COLS] = {26, 25, 33, 32};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
String inputPassword = "";
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Enter Password:");
}
void loop() {
char key = keypad.getKey();
if (key) {
if (key == '#') { // Submit button
lcd.clear();
if (inputPassword == PASSWORD) {
lcd.print("correct password!");
} else {
lcd.print("Wrong Password!");
}
delay(2000);
lcd.clear();
lcd.print("Enter Password:");
inputPassword = "";
} else if (key == '*') { // Clear input
inputPassword = "";
lcd.setCursor(0, 1);
lcd.print(" ");
} else { // Collect input
inputPassword += key;
lcd.setCursor(0, 1);
lcd.print(inputPassword);
}
}
}