/*Keypad example
by miliohm.com */
#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
String pad;
const byte numRows = 4;
const byte numCols = 4;
String password = "4321";
String msgA="A:Odaberi kut";
String msgB="B:Odaberi broj rupa";
String msg1="Kut je:";
String Ali="A";
char keypressed;
char mykey;
char keymap[numRows][numCols] =
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
//------------------------------------------------------------
byte rowPins[numRows] = { 9, 8, 7, 6 };
byte colPins[numCols] = { 5, 4, 3, 2 };
Keypad myKeypad = Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols); //mapping keypad
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print(msgA);
lcd.setCursor(0, 1);
lcd.print(msgB);
delay(1000);
}
void loop() {
// put your main code here, to run repeatedly:
readKeypad();
if (keypressed == 'A'){
lcd.clear();
lcd.print(msg1);
}
if (keypressed == '#') {
if (pad == password) {
lcd.setCursor(0, 1);
lcd.print("Access Granted");
} else {
lcd.setCursor(0, 1);
lcd.print("Access Denied");
}
} if (keypressed == '*') {
pad = "";
lcd.clear();
}
lcd.setCursor(0, 1);
lcd.print(pad);
delay(10);
}
void readKeypad() {
keypressed = myKeypad.getKey(); //deteksi penekanan keypad
if (keypressed != '#') {
String konv = String(keypressed);
pad += konv;
}
}