2min restricts
This commit is contained in:
parent
81239bb8f9
commit
247ac27ecc
73
src/main.cpp
73
src/main.cpp
@ -2,20 +2,47 @@
|
||||
#include <Ticker.h>
|
||||
|
||||
bool allow;
|
||||
bool error = false;
|
||||
|
||||
static const uint8_t WasserSensorPin = 14;
|
||||
static const uint8_t DruckSensorPin = 12;
|
||||
static const uint8_t SchuetzPin = 13;
|
||||
|
||||
static const int abschaltzeit = 1800;
|
||||
|
||||
static const int maxpumpdauer = 120;
|
||||
|
||||
Ticker tick;
|
||||
Ticker status;
|
||||
|
||||
//pumpendauer maximum ticker
|
||||
Ticker pumpendauer;
|
||||
|
||||
void pumpeSchalten(bool on) {
|
||||
// digitalWrite(4,on);
|
||||
if (allow) {
|
||||
digitalWrite(SchuetzPin, on);
|
||||
Serial.println("pumpe wird geschalten");
|
||||
if (on) {
|
||||
Serial.println("versuche Pumpe EIN zuschalten");
|
||||
} 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() {
|
||||
if (digitalRead(DruckSensorPin) == HIGH) {
|
||||
//pumpe einschalten
|
||||
Serial.println("Druck Sensor EIN");
|
||||
Serial.println("\n\nDruck Sensor EIN");
|
||||
if(digitalRead(WasserSensorPin)){
|
||||
Serial.println("Wasser Sensor EIN");
|
||||
pumpeSchalten(true);
|
||||
} else{
|
||||
//pumpe ausschalten
|
||||
Serial.println("Druck Sensor AUS");
|
||||
Serial.println("Wasser Sensor aus irgent einem Grund doch nicht ein -- sofort abschalten!");
|
||||
pumpeSchalten(false);
|
||||
}
|
||||
} else {
|
||||
//pumpe ausschalten
|
||||
Serial.println("\n\nDruck Sensor AUS");
|
||||
pumpeSchalten(false);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
int i = abschaltzeit; //todo better
|
||||
void WasserSensorCheck() {
|
||||
if (digitalRead(WasserSensorPin) == LOW) {
|
||||
Serial.println("Wasser Sensor AUS");
|
||||
@ -45,14 +77,29 @@ void WasserSensorCheck() {
|
||||
pumpeSchalten(false);
|
||||
|
||||
Serial.println("warte 30min");
|
||||
|
||||
status.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)) {
|
||||
allow = true;
|
||||
Serial.println("Einschalten der Pumpe wieder erlaubt.");
|
||||
|
||||
//pruefen ob drucksensor ein
|
||||
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() {
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
|
||||
pinMode(WasserSensorPin, INPUT);
|
||||
pinMode(DruckSensorPin, INPUT);
|
||||
|
||||
@ -78,8 +127,6 @@ void setup() {
|
||||
Serial.println("\n\n\n\nstartup of ESP");
|
||||
|
||||
|
||||
//digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
//initial measurement of water state
|
||||
delay(1000);
|
||||
//allow = digitalRead(WasserSensorPin);
|
||||
@ -87,6 +134,8 @@ void setup() {
|
||||
WasserSensorCheck();
|
||||
DruckschalterInt();
|
||||
|
||||
|
||||
//anhängen der Pin-Interrupts
|
||||
attachInterrupt(digitalPinToInterrupt(DruckSensorPin), DruckschalterInt, CHANGE);
|
||||
attachInterrupt(digitalPinToInterrupt(WasserSensorPin), WasserSensorInt, CHANGE);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user