#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd (0x27,16,2);
char P1 = '1'; char P2 = '2'; char P3 = '3'; char P4 = '4';
char C1, C2, C3, C4;
int roteLED = 13;
int grueneLED = 12;
const byte COLS = 4;
const byte ROWS = 4;
int z1 = 0, z2, z3, z4;
char hexaKeys[ROWS][COLS] = {
{'D','#','0','*'},
{'C','9','8','7'},
{'B','6','5','4'},
{'A','3','2','1'}
};
byte colPins[COLS] = {2,3,4,5};
byte rowPins[ROWS] = {6,7,8,9};
char Taste;
Keypad Tastenfeld = Keypad(makeKeymap(hexaKeys),rowPins,colPins,ROWS,COLS);
void setup() {
// put your setup code here, to run once:
lcd.init();
lcd.backlight();
Serial.begin(9600);
pinMode(roteLED,OUTPUT);
pinMode(grueneLED,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if(z1 == 0) {
lcd.setCursor(0,0);
lcd.print("Geben Sie den ");
lcd.setCursor(0,1);
lcd.print("Code ein: ");
}
Anfang:
Taste = Tastenfeld.getKey();
if(Taste) {
if(Taste == '*') {
lcd.setCursor(0,0);
lcd.print("Tuer verriegelt");
lcd.setCursor(0,1);
lcd.print(" ");
//delay(3000);
lcd.print(" ");
digitalWrite(roteLED,HIGH);
digitalWrite(grueneLED,LOW);
tone(10,50);
delay(3000);
noTone(10);
z1 = 0; z2 = 1; z3 = 1; z4 = 1;
goto Anfang;
}
if(Taste == '#') {
if(C1 == P1 && C2 == P2 && C3 == P3 && C4 == P4) {
lcd.setCursor(0,0);
lcd.print("Code korrekt,");
lcd.setCursor(0,1);
lcd.print("Schloss offen ");
digitalWrite(roteLED,LOW);
digitalWrite(grueneLED,HIGH);
tone(10,500);
delay(2000);
noTone(10);
}
else {
lcd.setCursor(0,0);
lcd.print("Code falsch, ");
lcd.setCursor(0,1);
lcd.print("Schloss gesperrt!");
digitalWrite(roteLED,HIGH);
digitalWrite(grueneLED,LOW);
tone(10,50);
delay(1000);
noTone(10);
z1 = 0; z2 = 1; z3 = 1; z4 = 1;
goto Anfang;
}
}
if(z1 == 0) {
C1 = Taste;
lcd.setCursor(0,0);
lcd.print("Geben Sie den ");
lcd.setCursor(0,1);
lcd.print("Code ein: * ");
tone(10,800);
delay(150);
noTone(10);
z1 = 1; z2 = 0; z3 = 1; z4 = 1;
goto Anfang;
}
if(z2 == 0) {
C2 = Taste;
lcd.setCursor(0,0);
lcd.print("Geben Sie den ");
lcd.setCursor(0,1);
lcd.print("Code ein: ** ");
tone(10,800);
delay(150);
noTone(10);
z1 = 1; z2 = 1; z3 = 0; z4 = 1;
goto Anfang;
}
if(z3 == 0) {
C3 = Taste;
lcd.setCursor(0,0);
lcd.print("Geben Sie den ");
lcd.setCursor(0,1);
lcd.print("Code ein: *** ");
tone(10,800);
delay(150);
noTone(10);
z1 = 1; z2 = 1; z3 = 1; z4 = 0;
goto Anfang;
}
if(z4 == 0) {
C4 = Taste;
lcd.setCursor(0,0);
lcd.print("Geben Sie den ");
lcd.setCursor(0,1);
lcd.print("Code ein: **** ");
tone(10,800);
delay(150);
noTone(10);
z1 = 1; z2 = 1; z3 = 1; z4 = 1;
}
}
}