#include <LiquidCrystal.h>
#include <Keypad.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
const int greenLed = 7;
const int redLed = 6;
const int rows = 4;
const int cols = 4;
char keys[rows][cols] =
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[rows] = {0, 1, 2, 3};
byte colPins[cols] = {A0, A1, A2, A3};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);
const int password = 1234;
int inputPassword = 0;
void setup() {
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("Enter Password:");
lcd.setCursor(0, 1);
}
void loop() {
char key = keypad.getKey();
if(key >= '0' && key <= '9') {
inputPassword = inputPassword * 10 + (key - '0');
lcd.print('*');
}
else if(key == '#') {
if(password == inputPassword){
digitalWrite(greenLed, HIGH);
}
else {
digitalWrite(redLed, HIGH);
}
}
}