2min restricts
This commit is contained in:
parent
81239bb8f9
commit
247ac27ecc
75
src/main.cpp
75
src/main.cpp
@ -2,20 +2,47 @@
|
|||||||
#include <Ticker.h>
|
#include <Ticker.h>
|
||||||
|
|
||||||
bool allow;
|
bool allow;
|
||||||
|
bool error = false;
|
||||||
|
|
||||||
static const uint8_t WasserSensorPin = 14;
|
static const uint8_t WasserSensorPin = 14;
|
||||||
static const uint8_t DruckSensorPin = 12;
|
static const uint8_t DruckSensorPin = 12;
|
||||||
static const uint8_t SchuetzPin = 13;
|
static const uint8_t SchuetzPin = 13;
|
||||||
|
|
||||||
|
static const int abschaltzeit = 1800;
|
||||||
|
|
||||||
|
static const int maxpumpdauer = 120;
|
||||||
|
|
||||||
Ticker tick;
|
Ticker tick;
|
||||||
|
Ticker status;
|
||||||
|
|
||||||
|
//pumpendauer maximum ticker
|
||||||
|
Ticker pumpendauer;
|
||||||
|
|
||||||
void pumpeSchalten(bool on) {
|
void pumpeSchalten(bool on) {
|
||||||
// digitalWrite(4,on);
|
// digitalWrite(4,on);
|
||||||
if (allow) {
|
if (on) {
|
||||||
digitalWrite(SchuetzPin, on);
|
Serial.println("versuche Pumpe EIN zuschalten");
|
||||||
Serial.println("pumpe wird geschalten");
|
|
||||||
} else {
|
} else {
|
||||||
Serial.println("Schalten des Schütz gesperrt durch Timeout");
|
Serial.println("versuche Pumpe AUS zuschalten");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allow && !error) {
|
||||||
|
if (on) {
|
||||||
|
pumpendauer.once(maxpumpdauer, []() { //erlaube keine einschaltung von mehr als 60 sek
|
||||||
|
if (digitalRead(DruckSensorPin)) {
|
||||||
|
//error zu lange
|
||||||
|
Serial.println("\n\npumpe lief mehr als 60 sekunden durchgaengig");
|
||||||
|
pumpeSchalten(false);
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
digitalWrite(SchuetzPin, on);
|
||||||
|
Serial.println("[Erfolg] pumpe wird geschalten");
|
||||||
|
} else {
|
||||||
|
Serial.println(
|
||||||
|
"[FEHLGESCHLAGEN] Schalten des Schütz gesperrt durch Timeout oder Fehler-- sofortiges ausschalten der pumpe\n");
|
||||||
|
digitalWrite(SchuetzPin, LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -24,17 +51,22 @@ void pumpeSchalten(bool on) {
|
|||||||
ICACHE_RAM_ATTR void DruckschalterInt() {
|
ICACHE_RAM_ATTR void DruckschalterInt() {
|
||||||
if (digitalRead(DruckSensorPin) == HIGH) {
|
if (digitalRead(DruckSensorPin) == HIGH) {
|
||||||
//pumpe einschalten
|
//pumpe einschalten
|
||||||
Serial.println("Druck Sensor EIN");
|
Serial.println("\n\nDruck Sensor EIN");
|
||||||
pumpeSchalten(true);
|
if(digitalRead(WasserSensorPin)){
|
||||||
|
Serial.println("Wasser Sensor EIN");
|
||||||
|
pumpeSchalten(true);
|
||||||
|
} else{
|
||||||
|
Serial.println("Wasser Sensor aus irgent einem Grund doch nicht ein -- sofort abschalten!");
|
||||||
|
pumpeSchalten(false);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
//pumpe ausschalten
|
//pumpe ausschalten
|
||||||
Serial.println("Druck Sensor AUS");
|
Serial.println("\n\nDruck Sensor AUS");
|
||||||
pumpeSchalten(false);
|
pumpeSchalten(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int i = abschaltzeit; //todo better
|
||||||
void WasserSensorCheck() {
|
void WasserSensorCheck() {
|
||||||
if (digitalRead(WasserSensorPin) == LOW) {
|
if (digitalRead(WasserSensorPin) == LOW) {
|
||||||
Serial.println("Wasser Sensor AUS");
|
Serial.println("Wasser Sensor AUS");
|
||||||
@ -45,14 +77,29 @@ void WasserSensorCheck() {
|
|||||||
pumpeSchalten(false);
|
pumpeSchalten(false);
|
||||||
|
|
||||||
Serial.println("warte 30min");
|
Serial.println("warte 30min");
|
||||||
|
|
||||||
|
status.detach();
|
||||||
tick.detach();
|
tick.detach();
|
||||||
tick.once(1800, []() {
|
|
||||||
|
i = abschaltzeit;
|
||||||
|
status.attach(5, []() {
|
||||||
|
i -= 5;
|
||||||
|
Serial.print("noch ");
|
||||||
|
Serial.print(i);
|
||||||
|
Serial.println(" Sekunden verbleibend");
|
||||||
|
});
|
||||||
|
|
||||||
|
tick.once(abschaltzeit, []() {
|
||||||
|
status.detach();
|
||||||
if (digitalRead(WasserSensorPin)) {
|
if (digitalRead(WasserSensorPin)) {
|
||||||
allow = true;
|
allow = true;
|
||||||
Serial.println("Einschalten der Pumpe wieder erlaubt.");
|
Serial.println("Einschalten der Pumpe wieder erlaubt.");
|
||||||
|
|
||||||
//pruefen ob drucksensor ein
|
//pruefen ob drucksensor ein
|
||||||
DruckschalterInt();
|
DruckschalterInt();
|
||||||
|
} else {
|
||||||
|
Serial.print("wassersensor immer noch kein Wasser --> verlaengern um 30min\n\n");
|
||||||
|
WasserSensorCheck();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -68,6 +115,8 @@ ICACHE_RAM_ATTR void WasserSensorInt() {
|
|||||||
void setup() {
|
void setup() {
|
||||||
pinMode(LED_BUILTIN, OUTPUT);
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
digitalWrite(LED_BUILTIN, LOW);
|
digitalWrite(LED_BUILTIN, LOW);
|
||||||
|
|
||||||
|
|
||||||
pinMode(WasserSensorPin, INPUT);
|
pinMode(WasserSensorPin, INPUT);
|
||||||
pinMode(DruckSensorPin, INPUT);
|
pinMode(DruckSensorPin, INPUT);
|
||||||
|
|
||||||
@ -78,15 +127,15 @@ void setup() {
|
|||||||
Serial.println("\n\n\n\nstartup of ESP");
|
Serial.println("\n\n\n\nstartup of ESP");
|
||||||
|
|
||||||
|
|
||||||
//digitalWrite(LED_BUILTIN, LOW);
|
|
||||||
|
|
||||||
//initial measurement of water state
|
//initial measurement of water state
|
||||||
delay(1000);
|
delay(1000);
|
||||||
//allow = digitalRead(WasserSensorPin);
|
//allow = digitalRead(WasserSensorPin);
|
||||||
allow=true;
|
allow = true;
|
||||||
WasserSensorCheck();
|
WasserSensorCheck();
|
||||||
DruckschalterInt();
|
DruckschalterInt();
|
||||||
|
|
||||||
|
|
||||||
|
//anhängen der Pin-Interrupts
|
||||||
attachInterrupt(digitalPinToInterrupt(DruckSensorPin), DruckschalterInt, CHANGE);
|
attachInterrupt(digitalPinToInterrupt(DruckSensorPin), DruckschalterInt, CHANGE);
|
||||||
attachInterrupt(digitalPinToInterrupt(WasserSensorPin), WasserSensorInt, CHANGE);
|
attachInterrupt(digitalPinToInterrupt(WasserSensorPin), WasserSensorInt, CHANGE);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user