#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <Servo.h>
//LCD
LiquidCrystal_I2C lcd(0x27, 16, 2);
//SERVO
Servo myServo;
int servoPin = 10;
int closedPosition = 0; // Locked
int openPosition = 90; // Unlocked
//KEYPAD
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
uint8_t rowPins[ROWS] = {9, 8, 7, 6};
uint8_t colPins[COLS] = {5, 4, 3, 2};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
//PASSWORD
String password = "090423"; // PASS
String inputP = "";
void setup() {
myServo.attach(servoPin);
myServo.write(closedPosition); // dapat naka lock muna
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("guess the pass!");
}
void loop() {
char key = keypad.getKey();
if (key) {
if (key == '#') { // "enter" key
if (inputP == password) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("happy 26th, bb!");
lcd.setCursor(0, 1);
lcd.print("i love you <3");
myServo.write(openPosition); // unlock if correct
delay(5000);
lcd.clear();
lcd.print("guess the pass!");
myServo.write(closedPosition); // lock again
} else {
lcd.clear();
lcd.print("Wrong Password");
delay(2000);
lcd.clear();
lcd.print("guess the pass!");
}
inputP = ""; // reset input
}
else if (key == '*') { // delete/reset
inputP = "";
lcd.clear();
lcd.print("guess the pass!");
}
else {
inputP += key;
lcd.setCursor(0, 1);
// Print * instead of the actual numbers
for (int i = 0; i < inputP.length(); i++) {
lcd.print('*');
}
}
}
}