#include <Wire.h>
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
#include<EEPROM.h>
LiquidCrystal_I2C lcd(0x27,16,2);
char password[6];
char pass[6],pass1[6];
int i=0;
char customKey=0;
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup()
{
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
lcd.begin(16, 2);
lcd.print("Masukan Password:");
lcd.setCursor(0,1);
for(int j=0;j<6;j++)
EEPROM.write(j, j+49);
for(int j=0;j<6;j++)
pass[j]=EEPROM.read(j);
}
void loop()
{
customKey = customKeypad.getKey();
if(customKey=='#')
change();
if (customKey)
{
password[i++]=customKey;
lcd.print(customKey);
}
if(i==6)
{
delay(200);
for(int j=0;j<6;j++)
pass[j]=EEPROM.read(j);
if(!(strncmp(password, pass,6)))
{
lcd.clear();
lcd.print(" Password Anda ");
lcd.setCursor(0,1);
lcd.print(" Benar ");
digitalWrite(13,HIGH);
delay(3000);
digitalWrite(13,LOW);
lcd.clear();
lcd.print("ACHMAD SYAIFUDIN");
lcd.setCursor(0,1);
lcd.print(" 191020100076 ");
delay(5000);
lcd.clear();
lcd.print("Masukan Password:");
lcd.setCursor(0,1);
i=0;
}
else
{
lcd.clear();
lcd.print(" Password Anda ");
lcd.setCursor(0,1);
lcd.print(" Salah ");
digitalWrite(12,HIGH);
delay(3000);
digitalWrite(12,LOW);
lcd.clear();
lcd.print("Masukan Password:");
lcd.setCursor(0,1);
i=0;
}
}
}
void change()
{
int j=0;
lcd.clear();
lcd.print("Password Lama :");
lcd.setCursor(0,1);
while(j<6)
{
char key=customKeypad.getKey();
if(key)
{
pass1[j++]=key;
lcd.print(key);
}
key=0;
}
delay(500);
if((strncmp(pass1, pass, 6)))
{
lcd.clear();
lcd.print("Password Salah");
lcd.setCursor(0,1);
lcd.print("Coba Lagi");
delay(1000);
}
else
{
j=0;
lcd.clear();
lcd.print("Password Baru :");
lcd.setCursor(0,1);
while(j<6)
{
char key=customKeypad.getKey();
if(key)
{
pass[j]=key;
lcd.print(key);
EEPROM.write(j,key);
j++;
}
}
lcd.clear();
lcd.print("Password Baru :");
lcd.setCursor(0,1);
lcd.print(" Tersimpan ");
delay(2000);
}
lcd.clear();
lcd.print("Masukan Password:");
lcd.setCursor(0,1);
customKey=0;
}