#include <Keypad.h>
#include <LiquidCrystal.h>
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
LiquidCrystal lcd(13, 12, 11, 10, 1, 0, 5, 4, 3, 2);
char password[] = "1212";
char input_password[5];
int index = 0;
bool is_correct = false;
void setup() {
lcd.begin(16, 2);
}
void loop() {
char key = keypad.getKey();
if (key != NO_KEY) {
if (key == '#' || index == 4) {
if (strcmp(input_password, password) == 0) {
lcd.clear();
lcd.print("on");
digitalWrite(LED_BUILTIN, HIGH);
is_correct = true;
} else {
lcd.clear();
lcd.print("not correct");
digitalWrite(LED_BUILTIN, LOW);
is_correct = false;
}
delay(1000);
lcd.clear();
index = 0;
memset(input_password, 0, sizeof(input_password));
} else {
input_password[index] = key;
index++;
}
}
}