#include <Servo.h>
#include<LiquidCrystal_I2C.h>
#include <Keypad.h>
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char inputPassword[7] = "";
int inputIndex = 0;
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
uint8_t colPins[COLS] = { 5, 4, 3, 2 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 9, 8, 7, 6 }; // Pins connected to R1, R2, R3, R4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
LiquidCrystal_I2C lcd(0x27, 16, 2);
Servo myServo;
int pos = 90;
int col2 = 0;
char pass[6] = { '1','2','3','4','5','6'};
void setup() {
myServo.attach(10);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("ENTER PASSWORD:");
Serial.begin(9600);
}
void loop() {
char key = keypad.getKey();
if (key) {
if (key == '*') {
inputIndex = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("WRONG INPUT");
clearInput();
myServo.write(0);
}
else if (key == '#') {
lcd.clear();
if (checkPassword()) {
lcd.print("WOW BUKAS");
myServo.write(180);
}
else {
lcd.print("WONK WONK");
myServo.write(0);
}
delay(2000);
lcd.clear();
lcd.print("ENTER PASSWORD: ");
inputIndex = 0;
clearInput();
}
else {
if (inputIndex < 6){
inputPassword[inputIndex] = key;
inputIndex++;
lcd.setCursor(0, 1);
lcd.print(inputPassword);
}
}
}
}
void clearInput() {
memset(inputPassword, 0, sizeof(inputPassword));
}
bool checkPassword(){
if (inputPassword[0] == pass[0]&&
inputPassword[1] == pass[1]&&
inputPassword[2] == pass[2]&&
inputPassword[3] == pass[3]&&
inputPassword[4] == pass[4]&&
inputPassword[5] == pass[5]){
return true;
} else{
return false;
}
}