#include <LiquidCrystal_I2C.h>
// jeremiah laman code for kepad 4x4
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
#include <Keypad.h>
String pindotin;
String sagot = "BCAD";
char pindot;
int led=A0;
int buzz=A1;
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
uint8_t colPins[COLS] = { 5, 4, 3, 2 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 9, 8, 7, 6 }; // Pins connected to R1, R2, R3, R4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.setCursor(2, 0);
lcd.print("welcome master");
lcd.setCursor(5, 1);
lcd.print("1Y4M");
delay(2000);
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("press # to enter");
lcd.setCursor(0, 0);
lcd.print("press * to clear");
delay(2000);
lcd.clear();
}
void loop() {
display();
readKeypad();
if (pindot == '#') {
if (pindotin == sagot) {
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Access Granted");
delay(1000);
digitalWrite(A0,HIGH);
digitalWrite(A1,LOW);
} else {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Try Again");
lcd.setCursor(0, 1);
lcd.print("Access Denied");
delay(2000);
digitalWrite(A0,LOW);
digitalWrite(A1,HIGH);
delay(100);
}
} if (pindot == '*') {
pindotin = "";
lcd.clear();
}
}
void readKeypad() {
pindot = keypad.getKey(); //deteksi penekanan keypad
if (pindot != '#') {
String congtv = String(pindot);
pindotin += congtv;
}}
void display(){
lcd.setCursor(0, 0);
lcd.print("password:");
lcd.print(pindotin);
delay(50);
lcd.setCursor(0, 1);
lcd.print("#-Enter||*-clear");
}