#include <LiquidCrystal.h>
#include <Keypad.h>
#define pass_len 7
LiquidCrystal lcd(22, 21, 20, 19, 18, 17);
char Data[pass_len];
char Master[pass_len] = "BCD246";
byte data_count = 0, master_count = 0;
bool pass_true;
char cus_key;
const uint8_t row = 4;
const uint8_t col = 4;
char keys[row][col] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
uint8_t rowPins[row] = {9, 8, 7, 6};
uint8_t colPins[col] = {5, 4, 3, 2};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, row, col);
void setup() {
}
void loop() {
lcd.setCursor(0,0);
lcd.print("Input Password:");
cus_key = keypad.getKey();
if (cus_key) // makes sure a key is actually pressed, equal to (customKey != NO_KEY)
{
Data[data_count] = cus_key; // store char into data array
lcd.setCursor(data_count,1); // move cursor to show each new char
lcd.print(Data[data_count]); // print char at said cursor
data_count++; // increment data array by 1 to store new char, also keep track of the number of chars entered
}
if(data_count == pass_len-1) // if the array index is equal to the number of expected chars, compare data to master
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Pwd ");
if(!strcmp(Data, Master)) // equal to (strcmp(Data, Master) == 0)
lcd.print("Accepted");
else
lcd.print("Denied");
delay(1000);// added 1 second delay to make sure the password is completely shown on screen before it gets cleared.
lcd.clear();
clearData();
}
}
void clearData()
{
while(data_count !=0)
{ // This can be used for any array size,
Data[data_count--] = 0; //clear array for new data
}
return;
}