#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
const byte Baris = 4;
const byte Kolom= 4;
int merah = 25;
int hijau = 26;
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] = {17, 16, 4, 2};
Keypad customKeypad = Keypad( makeKeymap(Keys), rowPins, colPins, Baris, Kolom);
char customKey;
int angka = 0;
int password = 555;
void setup() {
lcd.init ();
lcd.setBacklight(HIGH);
pinMode(merah, OUTPUT);
pinMode(hijau, OUTPUT);
}
void loop() {
lcd.setCursor(0,0);
lcd.print("Masukan Password");
customKey = customKeypad.getKey();
switch(customKey){
case '0' ... '9':
lcd.setCursor(0,1);
angka = angka * 10 + (customKey - '0');
lcd.print(angka);
break;
case '#':
if(angka == password){
lcd.setCursor(0,1);
lcd.print("Access Accepted ");
digitalWrite(hijau, HIGH);
digitalWrite(merah, LOW);
angka = 0;
lcd.clear();
}
else{
lcd.setCursor(0,1);
lcd.print("Invalid Password");
delay(2000);
digitalWrite(merah, HIGH);
digitalWrite(hijau, LOW);
angka = 0;
lcd.clear();
}
break;
case '*':
angka = 0;
lcd.clear();
break;
}
}