Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <EEPROM.h>
- #include <Keypad.h>
- //#include <LiquidCrystal.h>
- #include <LiquidCrystal_I2C.h>
- //LiquidCrystal lcd(7,6,5,4,3,2);
- LiquidCrystal_I2C lcd(0x27, 16, 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 [BARIS] = {11,9,8,7};
- byte pinKolom [KOLOM] = {6,5,4,3};
- Keypad keypad = Keypad(makeKeymap(tombol),pinBaris, pinKolom, BARIS,KOLOM);
- bool mode1=true; //digunakan untuk
- bool mode2=false;
- bool modeLampu = true;
- bool on=LOW;
- bool off=HIGH;
- const int relay=A3;
- long dtTombol=0; //menampung variabel tombol yg ditekan
- void setup() {
- Serial.begin(9600);
- pinMode(relay,OUTPUT);
- digitalWrite(relay,off);
- lcd.begin();
- 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() {
- char key=keypad.getKey();
- if(key){
- if(key=='A'){
- digitalWrite(relay,off);
- cekKeamanan("Password lama :", EEPROM.read(1));
- mode1=true;
- mode2=true;
- cekKeamanan("Password baru :", EEPROM.read(1));
- mode2=false;
- mode1=true;
- }
- if(key=='B'){
- modeLampu = !modeLampu;
- }
- }
- if(modeLampu){
- digitalWrite(relay,on);
- lcd.setCursor(0,0);
- lcd.print("Anda berada di");
- lcd.setCursor(0,1);
- lcd.print("dalam system...");
- }else{
- digitalWrite(relay,off);
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print("Berhasil keluar");
- }
- }
- 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=='*'){
- dtTombol=(dtTombol-dtTombol%10)/10;
- lcd.setCursor(0,1);
- lcd.print(" ");
- }else{
- dtTombol=dtTombol*10+key;
- }
- lcd.setCursor(0,0);
- lcd.print(str);
- lcd.setCursor(0,1);
- lcd.print(dtTombol);
- }
- }
- }
- }
- }
- //void keluar(){
- // digitalWrite(relay,off);
- // lcd.clear();
- // lcd.setCursor(0,0);
- // lcd.print("Berhasil keluar sistem.");
- //}
- //
Add Comment
Please, Sign In to add comment