// LCD1602 and Pi Pico!
#include <LiquidCrystal.h>
#include <Keypad.h>
#define Password_Lenght 7
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 colPins[COLS] = { 16, 17, 18, 19 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 20, 21, 22, 5 }; // Pins connected to R1, R2, R3, R4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
char Data[Password_Lenght];
char Master[Password_Lenght] = "A1B2C3";
byte data_count = 0, master_count = 0;
bool Pass_is_good;
void setup() {
lcd.begin(16, 2);
lcd.print("Input Password:");
lcd.setCursor(0, 1);
lcd.print("******");
}
void loop() {
delay(1);
char key = keypad.getKey();
if (key) // makes sure a key is actually pressed, equal to (customKey != NO_KEY)
{
Data[data_count] = 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 == Password_Lenght-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;
}