#include <Keypad.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(1, 3, 4, 5, 6, 7);
int TriggerUltraschall = 22; // Pin 22 Trigger Ultraschallensor Zisterne
int echoUltraschall = 23; // Pin 23 Echo Ultraschallensor Zisterne
int Wasserstand; // Variable Wasserstand
int Zisterneleer = 50; // Led Grün Pin 50
//int Zisternewarnung = 52; // Led Blau Pin 51
int Zisternenot = 51; // Led Gelb Pin 52
int Zisternevoll = 53; // Led Grün Pin 53
volatile boolean neuerdurchlauf = false; // Variable neuerdurchlauf bei Timer 1 ablauf
volatile boolean Bewegungan = false; // Variable neuerdurchlauf bei Timer 3 ablauf Bewegungsmelder
const int Bewegungssensor ;
int Sensorwert;
int letzterSensorwert = 0;
int Bewegungserkennung ;
int ein = 52; // Sensor für Manuelle Eingabe
int eingeben = 0; // inititalisieren Eingabe
long zisterneimpulsdauer; // ganzzahlige Impulsdauer
int varnot;
int varwarnung;
int Zisternefuellstand;
int relay = 34;
char Taste;
int Ventil1 = 36;
int x = 0;
int y = 0;
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char hexaKeys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {26, 27, 28, 29}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {30, 31, 32, 33}; //connect to the column pinouts of the keypad
//char Taste; //Taste ist die Variable der jeweils gedrückten Taste
//initialize an instance of class NewKeypad
Keypad Tastenfeld = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup()
{
pinMode(TriggerUltraschall, OUTPUT); // Pin 22 TriggerUltraschallsensor Ausgang
pinMode(echoUltraschall, INPUT); // Pin 23 Echo Ultraschallsensor Eingang
pinMode (Bewegungssensor, INPUT);
pinMode (ein,INPUT);
pinMode (relay, OUTPUT);
pinMode (Ventil1, OUTPUT);
delay(10);
lcd.begin(20,4);
}
void Bewegung()
{
Bewegungan = true; } // neuer durchlauf
void Zisterne()
{ // Neuer Durchlauf wenn Timer abgelaufen
digitalWrite(TriggerUltraschall, HIGH); // Pin TriggerUltraschallsensor setzen High
delayMicroseconds(20); // MIni Pause zum Werte schreiben
digitalWrite(TriggerUltraschall, LOW); // Pin TriggerUltraschallsensor setzen Low
zisterneimpulsdauer = pulseIn(echoUltraschall, HIGH); // Impulsdauer Ultraschallsensor Zisterne
Wasserstand = zisterneimpulsdauer * 0.03432 / 2; // Impulsdauer * Schallgeschwindigkeit 0,03432cm /2 wegen Echo
lcd.clear(); // Clears the display
delay(100);
lcd.setCursor(0,0);
lcd.print("Wasserstand:"); // Prints "Arduino" on the LCD
lcd.setCursor(0,1);
lcd.print(Wasserstand); lcd.print(" cm");
lcd.setCursor(0,2);
if (Wasserstand <=50){Zisternefuellstand=1;lcd.print("Voll"); }
if (Wasserstand >50 && Wasserstand <=99){ Zisternefuellstand=2; lcd.print(" = Normal"); }
if (Wasserstand >=100 && Wasserstand <=199){Zisternefuellstand=3; lcd.print(" = Notbetrieb"); }
if (Wasserstand >= 200){Zisternefuellstand=4; lcd.print(" = Fastleer "); }
}
void Manuel()
{ lcd.clear();
lcd.setCursor(0,0);
lcd.print ("1 fuer Zisterne");
lcd.setCursor(0,1);
lcd.print ("2 fuer Pool");
lcd.setCursor(0,2);
lcd.print ("3 fuer Garten");
lcd.setCursor(0,3);
lcd.print ("3 fuer Sonstiges ");
do{
Taste = Tastenfeld.getKey();
if (Taste)
{y=y*10 + (Taste-48) ;x++;}
else {x=0;}
//delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(y);
}
while(x<0);
switch (y){
case '0': lcd.clear();lcd.setCursor(0,0); lcd.print ("Variable Einstellen");delay(1000); lcd.setCursor(0,1);lcd.print ("1 fuer Notbetrieb.");lcd.setCursor(0,2);lcd.print ("2 fuer Warnbetrieb.");
case '2': lcd.clear();lcd.setCursor(0,0);lcd.print ("2");delay(1000);
case '3': lcd.clear();lcd.setCursor(0,0);lcd.print ("3");delay(1000);
case '4': lcd.clear();lcd.setCursor(0,0);lcd.print ("4");delay(1000);
default: break;
}
Taste = Tastenfeld.getKey();
//lcd.clear(); lcd.setCursor(0,0); lcd.print("Gib zweistellige Zahl"); lcd.clear(); lcd.setCursor(0,1); lcd.print(" in % ein");lcd.setCursor(0,3); lcd.print("Neue Variable: ");
lcd.blink();
if (Taste)
{
y=y*10 + (Taste-48) ;
lcd.print(y);
}
else exit;
}
void loop()
{
Zisterne ();
//Bewegungerkannt ();
x==0;
if (digitalRead(ein)==HIGH) { Manuel();}
// delay(1000);
//digitalWrite(relay, HIGH);digitalWrite(Ventil1, HIGH);
}
//delay(3000);
//lcd.noBlink(); // Turns off the blinking LCD cursor
//lcd.cursor(); // Displays an underscore (line) at the position to which the next character will be written
//delay(4000);
//lcd.noCursor(); // Hides the LCD cursor
//lcd.clear();
// Serial.println(Wasserstand);