#include <LiquidCrystal.h>
#include <Keypad.h>
#define Buzzer 13
#define Led 11
char* password ="11111";
int posisi = 0;
const byte rows = 4;
const byte cols = 4;
char keyMap [rows] [cols]=
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins [rows] = {2, 3, 4, 5};
byte colPins [cols] = {6, 7, 8, 9};
Keypad myKeypad = Keypad( makeKeymap(keyMap), rowPins, colPins, rows, cols);
LiquidCrystal lcd (A5, A4, A3, A2, A1, A0); // (RS,E,D4,D5,D6,D7)
void setup ()
{
lcd.begin(16, 2);
pinMode(Buzzer, OUTPUT);
pinMode(Led, OUTPUT);
setLocked (true);
}
void loop()
{
char whichKey = myKeypad.getKey();
lcd.setCursor(4, 0);
lcd.print("Silahkan");
lcd.setCursor(0, 1);
lcd.print(" Ketik password");
if(whichKey == '*' || whichKey == '#' || whichKey == 'A' ||
whichKey == '*' || whichKey == 'C' || whichKey == 'D' || whichKey == '0')
{
posisi=0;
setLocked(true);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Pasword salah");
lcd.setCursor(0,1);
lcd.print(" Ulangi lagi");
tone(Buzzer,2000,200);
delay(1000);
lcd.clear();
}
if(whichKey == password [posisi])
{
posisi ++;
}
if(posisi == 5)
{
setLocked (false);
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("*** SUKSES ***");
delay(5000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("HAI... Kenalin");
lcd.setCursor(0, 1);
lcd.print(" Namaku Resti");
delay(5000);
lcd.clear();
}
delay(100);
}
void setLocked(int locked)
{
if(locked)
{
digitalWrite(Led, LOW);
noTone(Buzzer);
}
else
{
digitalWrite(Led, HIGH);
tone(Buzzer,1535,500);
}
}