#include <Keypad.h>
#include <LiquidCrystal_I2C.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] = {13, 12, 14, 27};
byte colPins[COLS] = {26, 25, 33, 32};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
char customKey; //Variabel penampung input keypad
int number = 0; //Variabel penampung nilai angka
int password = 1234; //Password
LiquidCrystal_I2C lcd(0x27, 16, 2);
int i = 0;
void setup(){
lcd.init();
lcd.backlight();
}
void loop()
{
lcd.setCursor(0,0);
lcd.print("Input Password"); //Tampilan pada layar LCD
customKey = keypad.getKey(); //Baca input keypad
//------------Prosedur jika input berupa angka------------//
switch(customKey){
case '0' ... '9':
lcd.setCursor(i,1);
number = number * 10 + (customKey - '0');
lcd.print("*");
i++;
break;
//------------Jika input '#' maka cek password------------//
case '#':
if(number == password){ //Jika password benar, maka
lcd.setCursor(0,1);
lcd.print("Access Accepted "); //Tampilan LCD
delay(2000);
number = 0;
i = 0;
lcd.clear();
}
else{ //Jika salah, maka
lcd.setCursor(0,1);
lcd.print("Invalid Password"); //Tampilan LCD
delay(2000);
number = 0;
i = 0;
lcd.clear();
}
break;
//------------Jika input '*' maka hapus tampilan------------//
case '*':
number = 0;
i = 0;
lcd.clear();
break;
}
}