#include <LiquidCrystal.h>
#include <Keypad.h>
/* Display */
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
/* Keypad setup */
const byte KEYPAD_ROWS = 4;
const byte KEYPAD_COLS = 4;
byte rowPins[KEYPAD_ROWS] = {5, 4, 3, 2};
byte colPins[KEYPAD_COLS] = {A3, A2, A1, A0};
char keys[KEYPAD_ROWS][KEYPAD_COLS] = {
{'1', '2', '3', 'a'},
{'4', '5', '6', 'b'},
{'7', '8', '9', 'c'},
{'*', '0', '#', 'd'}
};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, KEYPAD_ROWS, KEYPAD_COLS);
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
/* led pin 6 */
pinMode(6, OUTPUT);
pesanAwal();
}
bool statusKunci = false;
bool statusEnroll = false;
//char key = "";
void loop() {
lcd.setCursor(0, 0);
updateCursor();
//char key = 'a';
char key = keypad.getKey();
if (key) {
if(statusKunci == false){
tampilMengunciSepeda();
lcd.setCursor(10, 1);
updateCursor();
//delay (2000);
//lcd.clear();
//char key = keypad.getKey();
char key2 = key;
lcd.print(key2);
switch (key2) {
case 'a':
statusKunci = true;
digitalWrite(6, HIGH);
tampilKunciBerhasil();
return;
default:
statusKunci = false;
tampilKunciGagal();
return;
}
delay (2000);
lcd.clear();
}
/*
if(statusKunci == false) {
lcd.print("kunci ?");
lcd.setCursor(10, 1);
//char key2 = keypad.getKey();
lcd.print(key);
} */
}
}
void pesanAwal() {
// bagian ini untuk menampilkan tulisan awal
lcd.print("Sistem pengunci");
lcd.setCursor(0, 1);
lcd.print("Sepeda di ruang");
delay(500);
lcd.clear();
lcd.setCursor(5, 0);
lcd.print("publik ");
lcd.setCursor(3, 1);
lcd.print("- arduino");
delay(500);
lcd.clear();
}
void updateCursor() {
if (millis() / 250 % 2 == 0 ) {
lcd.cursor();
} else {
lcd.noCursor();
}
}
void processInput(char key) {
}
void tampilMengunciSepeda() {
lcd.setCursor(0, 0);
lcd.print("Saat ini terbuka");
delay(500);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Ingin mengunci ?");
delay(50);
lcd.setCursor(0, 1);
lcd.print("(A = Ya)");
delay (2000);
}
void tampilKunciBerhasil() {
lcd.setCursor(0, 0);
lcd.print("Berhasil Kunci");
delay(600);
lcd.clear();
}
void tampilKunciGagal() {
lcd.setCursor(0, 0);
lcd.print("Gagal Kunci");
delay(600);
lcd.clear();
}