#include <XNode.h>
#include <Keypad_I2C.h>
#include <Keypad.h>
#include <Wire.h>
#define I2CADDR 0x38
const byte anzZeilen = 4;
const byte anzSpalten = 4;
char tastenLayout[anzZeilen][anzSpalten] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte zeilenPins[anzZeilen] = {0, 1, 2, 3};
byte spaltenPins[anzSpalten] = {4, 5, 6, 7};
Keypad_I2C i2cKeypad( makeKeymap(tastenLayout), zeilenPins, spaltenPins, anzZeilen, anzSpalten, I2CADDR);
int redLed = 15;
int greenLed = 16;
int piezo = 2;
String input ="";
String password ="1234";
String clearPW ="*";
String key = "";
int output_pin = 12;
int output_virus_pin = 3;
int input_pin = 14;
int input_virus_pin = 13;
XNode node(input_pin, output_pin, input_virus_pin, output_virus_pin);
boolean action = false;
void setup (){
node.init();
i2cKeypad.begin( );
Serial.begin(115200);
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(piezo, OUTPUT);
digitalWrite(greenLed, LOW);
digitalWrite(redLed, HIGH);
Serial.println("Setup done");
}
void loop(){
char ausgeleseneTaste = i2cKeypad.getKey();
key = ausgeleseneTaste;
Serial.println(ausgeleseneTaste);
if (ausgeleseneTaste != NO_KEY){
Serial.print("Passwort: ");
input.concat(key);
Serial.println(input);
}
if (input.equals(password)){
Serial.println("Password correct");
digitalWrite(redLed, LOW);
digitalWrite(greenLed, HIGH);
node.send();
tone(piezo, 500);
delay(300);
noTone(piezo);
delay(50);
tone(piezo, 300);
delay(200);
noTone(piezo);
delay(1000);
digitalWrite(greenLed, LOW);
digitalWrite(redLed, HIGH);
}
int lengthPW = input.length();
if (lengthPW > 3){
input = "";
}
if (key == clearPW){
input = "";
digitalWrite(greenLed, LOW);
digitalWrite(redLed, HIGH);
}
if (lengthPW > 3 && input != password){
digitalWrite(redLed, LOW);
tone(piezo, 100);
delay(200);
digitalWrite(redLed, HIGH);
noTone(piezo);
}
}