#include <Keypad.h>
const byte ROWS = 4; //jumlah baris
const byte COLS = 4; //jumlah kolom
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}; // Koneksi pin baris
byte colPins[COLS] = {5, 4, 3, 2}; // Koneksi pin kolom
String password = "1234"; // Password yang di inginkan
String key_pass = "";
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup(){
Serial.begin(9600);
pinMode(13,OUTPUT);
}
void loop(){
char customKey = customKeypad.getKey();
if (customKey){
if(customKey == '*') {
if(key_pass == password) {
Serial.println("Password Benar");
digitalWrite(13,HIGH);
delay(5000);
digitalWrite(13,LOW);
key_pass = "";
} else {
Serial.println("Password Salah! Ulangi lagi");
key_pass = "0";
}
} else if(customKey == 'D') {
Serial.println("Data Input dihapus, Silahkan Masukan Password lagi");
key_pass = "";
} else {
key_pass += customKey;
Serial.println(key_pass);
}
}
}