#include <Servo.
h>
#include <Keypad.h>
#include <LiquidCrystal.h>
#define led 13
Servo servo;
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] = {11, 10, 9, 8};
byte colPins[COLS] = {7, 6, 5, 4};
Keypad kp = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
const int rs = A0, en = A1, d4 = A2, d5 = A3, d6 = A4, d7 = A5;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
char correctPass[] = "1234";
int number = sizeof(correctPass) - 1;
char pass[sizeof(correctPass) - 1];
int i = 0, counter = 0;
bool door = 1;
void setup() {
pinMode(led, OUTPUT);
[Link](3);
[Link](16, 2);
[Link]("Enter the Pass");
[Link](0);
[Link](0, 1);
}
void loop() {
if (door == 0) {
char key = [Link]();
if (key == 'A') {
[Link](0);
i = counter = 0;
[Link]();
[Link]("Enter the pass");
[Link](0, 1);
door = 1;
}
} else {
char key = [Link]();
if (key >= '0' && key <= '9') {
[Link]('*');
pass[i] = key;
i++;
} else if (key == '#') {
if (i == number) {
for (int j = 0; j < number; j++) {
if (pass[j] == correctPass[j]) counter++;
}
if (counter == number) {
correct();
} else {
wrong();
}
} else {
wrong();
}
}
}
}
void wrong() {
[Link]();
[Link](0, 0);
[Link]("Wrong Pass ");
[Link](0, 1);
[Link](" Try Again ");
delay(2000);
i = 0;
counter = 0;
[Link]();
[Link](0, 0);
[Link]("Enter the Pass");
[Link](0, 1);
}
void correct() {
[Link]();
[Link](0, 0);
[Link]("Correct Pass ");
delay(2000);
[Link]();
[Link](0, 0);
[Link]("The door is open");
[Link](0, 1);
[Link]("<A> To close");
[Link](90);
delay(1000);
i = 0;
counter = 0;
door = 0;
}