#include <EEPROM.h>
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const byte LEDMERAH = 2;
const int BARIS = 4;
const int KOLOM = 4;
char tombol[BARIS][KOLOM] = {
{1, 2, 3, 'A'},
{4, 5, 6, 'B'},
{7, 8, 9, 'C'},
{'*',0, '#','D'}
};
byte pinBaris [KOLOM] = {9,8,7,6};
byte pinKolom [BARIS] = {13,12,11,10};
Keypad keypad = Keypad(makeKeymap(tombol),pinKolom, pinBaris, BARIS,KOLOM);
bool mode1=true;
bool mode2=false;
bool on=HIGH;
bool off=LOW;
// const int relay=0;
long dtTombol=0;
void setup() {
Serial.begin(9600);
// pinMode(relay,OUTPUT);
pinMode(LEDMERAH,OUTPUT);
digitalWrite(LEDMERAH,off);
lcd.begin(16,2);
Serial.println(EEPROM.read(0));
cekKeamanan("User ID", EEPROM.read(0));
mode1=true;
cekKeamanan("Password", EEPROM.read(1));
mode1=true;
lcd.clear();
lcd.setCursor(5,0);
lcd.print("Akses");
lcd.setCursor(3,1);
lcd.print("diijinkan");
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Loading.");
delay(700);
for(int i=1; i<=5; i++){
lcd.setCursor(i+7,0);
lcd.print(".");
delay(700);
}
}
void loop() {
lcd.setCursor(0,0);
lcd.print("Anda berada di");
lcd.setCursor(0,1);
lcd.print("dalam system...");
char key=keypad.getKey();
if(key){
if(key=='A'){
digitalWrite(LEDMERAH,off);
cekKeamanan("Password lama :", EEPROM.read(1));
mode1=true;
mode2=true;
cekKeamanan("Password baru :", EEPROM.read(1));
mode2=false;
mode1=true;
}
}
digitalWrite(LEDMERAH,on);
}
void cekKeamanan(String str, byte data){
lcd.clear();
dtTombol=0;
lcd.setCursor(0,0);
lcd.print(str);
while(mode1){
char key = keypad.getKey();
if(key){
if(key == 'D'){
if(mode2){
EEPROM.write(1,dtTombol);
lcd.setCursor(0,0);
lcd.print("Password ");
lcd.setCursor(0,1);
lcd.print("diperbaharui");
for(int i=1; i<=3; i++){
lcd.setCursor(i+11,1);
lcd.print(".");
delay(700);
}
mode1=false;
}
if(!mode2){
if(dtTombol==data){
mode1=false;
}else{
lcd.setCursor(0,1);
lcd.print(" invalid");
delay(1500);
cekKeamanan(str,data);
}
}
}else{
if(key!='A' && key!='B' && key!='C' && key!='#'){
if(key=='*'){ //hapus angka
dtTombol=(dtTombol-dtTombol%10)/10;
lcd.setCursor(0,1);
lcd.print(" ");
}else{
dtTombol=dtTombol*10+key; //input angka
}
lcd.setCursor(0,0);
lcd.print(str);
lcd.setCursor(0,1);
lcd.print(dtTombol);
}
}
}
}
}