#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
const uint8_t BARIS=4;
const uint8_t KOLOM=4;
char keys[BARIS][KOLOM]={
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
uint8_t rowPins[BARIS]={14,12,19,18};
uint8_t colPins[KOLOM]={5,4,2,15};
Keypad customKeypad= Keypad(makeKeymap(keys), rowPins, colPins,BARIS,KOLOM);
char customKey;
int number = 0;
int password = 1379;
void setup() {
lcd.init();
lcd.setBacklight(HIGH);
}
void loop() {
lcd.setCursor(0,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){ //Jika password benar, maka
lcd.setCursor(0,1);
lcd.print("Access Accepted "); //Tampilan LCD
number = 0;
lcd.clear();
}
else{ //Jika salah, maka
lcd.setCursor(0,1);
lcd.print("Invalid Password"); //Tampilan LCD
delay(2000);
number = 0;
lcd.clear();
}
break;
case '*':
number = 0;
lcd.clear();
break;
}
}