//******************Notes*********************
// Press # to submit the password after entering it
// Press * to reset the entered password
// Hide the password characters using *
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
#define redLED 11
#define greenLED 12
#define I2C_ADDR 0x27
#define LCD_COLUMNS 16
#define LCD_LINES 2
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
const int numRows = 4;
const int numCols = 4;
const int debounceTime = 20;
const char keymap[numRows][numCols] = {
{ '1', '2', '3' ,'A' },
{ '4', '5', '6','B' },
{ '7', '8', '9','C' },
{ '*', '0', '#','D' }
};
const byte rowPins[numRows] = {9, 8, 7, 6};
const byte colPins[numCols] = {5, 4, 3, 2};
Keypad keypad = Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);
String password = "abcd123";
String input = "";
void setup() {
pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Enter Password:");
lcd.setCursor(0, 1);
}
void loop() {
char key = keypad.getKey();
if (key != NO_KEY) {
if (key == '#') {
input.toLowerCase();
if (input == password) {
digitalWrite(greenLED, HIGH);
digitalWrite(redLED, LOW);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Correct Password");
} else {
digitalWrite(greenLED, LOW);
digitalWrite(redLED, HIGH);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Incorrect");
lcd.setCursor(0, 1);
lcd.print("Password");
}
delay(2000);
resetSystem();
}
else if (key == '*') {
input = "";
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Password:");
lcd.setCursor(0, 1);
}
else {
input += key;
lcd.print('*');
}
}
}
void resetSystem() {
input = "";
digitalWrite(redLED, LOW);
digitalWrite(greenLED, LOW);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Password:");
lcd.setCursor(0, 1);
}