//------------------------------------------------Include|
#include <Keypad.h>
#include <LiquidCrystal.h>
//------------------------------------------------setup|
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
void setup() {
lcd.begin(16, 2); }
//------------------------------------------------pinPad|
#define passLength 16
char userInput[passLength];
char Master[passLength] = "1234"; //change the numbers in the "" to change the password
char customKey;
byte pressCount = 0;
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', 'D' },
{ 'E', '0', 'C', 'F' }
};
uint8_t colPins[COLS] = { 18, 19, 20, 21 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 14, 15, 16, 17 }; // Pins connected to R1, R2, R3, R4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
//------------------------------------------------password, clear and check|
void password(){ //checks what number is pressed
customKey = keypad.waitForKey(); //waits until a button is pressed
if(customKey != 'E' && customKey != 'C'){ //if anything except clear and enter button is pressed
userInput[pressCount] = customKey;
lcd.setCursor(pressCount,1);
lcd.print("*"); //if you input a number it prints a *
pressCount++; } else {
check(); //if a clear or enter button is pressed
} }
void clearData() { //code to clear
while (pressCount != 0) {
userInput[pressCount] = 0;
pressCount--; }
setup();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Password:");
lcd.setCursor(0,0); }
void check(){ //code that checks if e or c is pressed
if(customKey == 'E'){
if (!strcmp(userInput, Master)){
//what happens if you put in the correct password
clearData();
} else if (strcmp(userInput, Master)){
//what happens if you put in the incorrect password
clearData();
} }
if(customKey == 'C'){ //clear button
clearData(); } }
//------------------------------------------------loop|
void loop() {
password();
}