#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
LiquidCrystal_I2C lcd(0x27,16,2);
const byte Baris = 4;
const byte Kolom = 4;
char keys[Baris][Kolom] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[Baris] = {14, 12, 19, 18};
byte colPins[Kolom] = {5, 4, 2, 15};
Keypad customkeypad = Keypad( makeKeymap(keys), rowPins, colPins, Baris, Kolom);
char customkey;
int number = 0;
int password = 13102005;
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
}
void loop() {
lcd.setCursor(1,0);
lcd.print("Input Password");
customkey = customkeypad.getKey();
switch(customkey){
case '0' ... '9':
lcd.setCursor(0,1);
number = number * 10 + (customkey - '0');
lcd.print(number);
break;
case '#':
if(number == password){
lcd.setCursor(0,1);
lcd.print("Access Guaranted");
delay(2000);
number = 0;
lcd.clear();
}
else{
lcd.setCursor(0,1);
lcd.print("Invalid Password");
delay(2000);
number = 0;
lcd.clear();
}
break;
case '*':
number = 0;
lcd.clear();
break;
}
}