#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
#include <ESP32Servo.h>
Servo servo;
Servo servo1;
LiquidCrystal_I2C lcd(0x27,16,2);
const byte baris = 4;
const byte kolom = 4;
char pin[baris][kolom]= {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte pinbaris[baris] = {16,17,18,19};
byte pinkolom[kolom] = {15,2,23,4};
Keypad kiped = Keypad( makeKeymap(pin),pinbaris, pinkolom, baris, kolom);
int num = 0 ;
int pasword1= 1234;
int pasword2 = 2345 ;
void setup(){
Serial.begin(9600);
servo.attach(12);
servo1.attach(14);
lcd.init();
lcd.setBacklight(HIGH);
}
void loop(){
char tombol = kiped.getKey();
switch(tombol){
case '0' ... '9':
num = num * 10 + (tombol - '0');
lcd.setCursor(0,0);
lcd.print(num);
break;
case '#':
if(num == pasword1){
lcd.setCursor(0,0);
lcd.print("pasword benar");
servo1.write(180);
num = 0;
}
else if (num == pasword2){
lcd.setCursor(0,0);
servo.write(180);
lcd.print("pasword betul");
delay(5000);
num = 0 ;
lcd.clear();
}
break;
case '*':
num = 0;
lcd.clear();
break;
}
}