#include <LiquidCrystal_I2C.h> /*include LCD I2C Library*/
#include <Keypad.h>
#define Password_Length 5
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[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 customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
//changed address for simulation.. ~q
LiquidCrystal_I2C lcd(0x27, 16, 2); /*I2C scanned address defined + I2C screen size*/
char Data[Password_Length];
char Master[Password_Length] = "1234";
byte data_count = 0, master_count = 0;
char customKey;
int num = 1;
void setup() {
lcd.init(); /*LCD display initialized*/
lcd.clear(); /*Clear LCD Display*/
lcd.backlight(); /*Turn ON LCD Backlight*/;
Serial.begin(9600);
}
void loop() {
if (data_count < Password_Length - 1) {
lcd.setCursor(0, 0); /*Set cursor to Row 1*/
lcd.print("Zadej heslo"); /*print text on LCD*/
customKey = customKeypad.getKey();
if (customKey) {
Data[data_count] = customKey;
lcd.setCursor(data_count, 1);
lcd.print(Data[data_count]);
data_count++;
}
}
if (data_count == Password_Length - 1) {
lcd.clear();
if (!strcmp(Data, Master)) {
lcd.print("Spravne");
delay(2000);
}
else {
lcd.print("Spatne");
num++;
data_count = 0;
delay(1000);
if (num == 4) {
lcd.clear();
lcd.print("3x spatne");
delay(2000);
lcd.clear();
lcd.print("Blokuji");
delay(2000);
lcd.noDisplay();
}
}
}
}