#include <Keypad.h>
#include <LiquidCrystal.h>
#include <Password.h>
const int ROW_NUM = 4; // Four rows
const int COLUMN_NUM = 4; // Four columns
char keys[ROW_NUM][COLUMN_NUM] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte pin_rows[ROW_NUM] = {9, 8, 7, 6}; // Row pin connections of the keypad
byte pin_column[COLUMN_NUM] = {5, 4, 3, 2}; // Column pin connections of the keypad
Keypad keypad = Keypad(makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM);
char inputArray[5]; // Changed it to include the star as part of the password
char Access[5] = {'1', '2', '3', '4', '*'}; // Universal password
int i = 0;
int attempts = 0; // Number of attempts made
LiquidCrystal lcd(51, 49, 47, 45, 43, 41); // Assign pins to LCD display
void setup()
{
lcd.begin(16, 2);
lcd.clear();
lcd.print("PALADIN ALARM");
}
void loop()
{
delay(3000);
login();
}
void login() // Code attempts and system arming
{
lcd.clear();
lcd.print("PALADIN ALARM");
lcd.setCursor(0, 1);
lcd.print("ARM CODE: ");
while (attempts < 3)
{
char key = keypad.getKey();
if (key)
{
inputArray[i] = key;
i++;
lcd.print(key);
if (key == '#')
{
lcd.print("Reset");
i = 0;
}
if (i == 5)
{
if (checkPassword())
{
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Correct");
delay(2000);
lcd.clear();
active();
}
else
{
lcd.clear();
lcd.print("INCORRECT");
delay(3000);
lcd.clear();
i = 0;
attempts++;
}
}
}
}
if (attempts == 3)
{
alarming();
}
}
bool checkPassword()
{
for (int j = 0; j < 4; j++)
{
if (inputArray[j] != Access[j])
{
return false;
}
}
return true;
}
void alarming()
{
lcd.clear();
lcd.print("**ALARMING**");
digitalWrite(25, HIGH);
tone(25, 1000, 1000);
}
void active()
{
lcd.print("PALADIN ALARM");
lcd.setCursor(0, 1);
lcd.print("***Active***");
disarm();
}
void inactive()
{
lcd.clear();
lcd.print("Deactivated");
delay(3000);
login();
}
void disarm()
{
lcd.clear();
lcd.print("Alarm Active");
lcd.setCursor(0, 1);
lcd.print("DISARM CODE: ");
i = 0;
while (attempts < 3)
{
char key = keypad.getKey();
if (key)
{
inputArray[i] = key;
i++;
lcd.print(key);
if (key == '#')
{
lcd.print("Reset");
i = 0;
}
if (i == 5)
{
if (checkPassword())
{
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Correct");
delay(2000);
lcd.clear();
inactive();
}
else
{
lcd.clear();
lcd.print("INCORRECT");
delay(3000);
lcd.clear();
attempts++;
}
}
}
}
if (attempts == 3)
{
alarming();
}
}