#include <Wire.h>
#include <Servo.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
char keys[4][4] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[4] = {13, 12, 11, 10};
byte colPins[4] = {9, 8, 7, 6};
Keypad kp = Keypad( makeKeymap(keys), rowPins, colPins, 4, 4);
Servo sv;
void setup() {
lcd.begin(20, 4);
sv.attach(5);
sv.write(0);
lcd.setCursor(0, 0);
lcd.print(" Welcome to the");
lcd.setCursor(0, 1);
lcd.print(" Locker System!");
delay(2000);
lcd.clear();
lcd.print("Press A to Open the");
lcd.setCursor(0, 1);
lcd.print("Locker!!!");
}
bool isEnteringPswd = false;
String enteringPswd = "";
String correctPswd = "12345";
void loop() {
char key = kp.getKey();
if (key != NO_KEY) {
if (isEnteringPswd) {
lcd.noBlink();
if (key == 'A') {
if (enteringPswd == correctPswd) {
lcd.clear();
lcd.print("Locker is Opening!!!");
sv.write(150);
delay(2000);
lcd.clear();
lcd.print("Locker Opened!");
}else{
}
} else {
enteringPswd = enteringPswd + key;
lcd.print(key);
}
} else {
if (key == 'A') {
lcd.clear();
lcd.print("Enter Password:");
lcd.setCursor(0, 1);
lcd.blink();
isEnteringPswd = true;
}
}
}
}