Hello everybody,
I have a problem with my project.
I build this project for my garden watering.
The idea is to start the different valves one after the other, then a short brake and start them again.
Everything works. But now I have the problem to stop the switch case function befor the statement is ended.
Anyone a idea how to solve the problem?
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h> // here is the SimpleTimer library
#include <SPI.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
BlynkTimer timer;
WidgetRTC rtc;
int Countdown; // Global variable used in Slider widget and runEveryMinute()
bool ONstatus = false; // variable to switch device ON and OFF
// Ampel Belegung der Ausgaenge
const byte GELBPin = D0;
const byte GRUENPin = D1;
const byte BLAUPin = D2;
//
const boolean ein = HIGH;
const boolean aus = LOW;
//
int ZEITBEWAESSERUNG;
int ZEITPAUSE;
//const int ZEITROTPHASE = 3000;
//const int ZEITGELBPHASE = 3000;
unsigned long ampelMillis;
unsigned long ampelIntervall;
//
enum ZUSTAENDE {ZUSTAND1, ROTGELB, GRUEN, GELB, PAUSE, ZUSTAND2, ZUSTAND3, ZUSTAND4, ZUSTAND5};
byte zustand = ZUSTAND1;
//enum ZUSTAENDE {ROT, ROTGELB, GRUEN, GELB, PAUSE, ZUSTAND1, Zustand2, Zustand3, Zustand4, Zustand5};
int valueAN;
int Starten;
char auth[] = "********************"; //BLYNK SERVER RASPI
char ssid[] = "*************";
char pass[] = "********************";
BLYNK_CONNECTED() {
// Request the latest state from the server
Blynk.syncAll();
// Alternatively, you could override server state using:
//Blynk.virtualWrite(V2, ledState);
}
BLYNK_WRITE(V1) //Starten Intervall
{
valueAN = param.asInt();
}
BLYNK_WRITE(V2) { // add a slider to your project on V0 range 0 to 30 (minutes)
ZEITPAUSE = param.asInt(); // set variable as Slider value
}
BLYNK_WRITE(V3) { // add a slider to your project on V0 range 0 to 30 (minutes)
ZEITBEWAESSERUNG = param.asInt(); // set variable as Slider value
}
void Ventile(){ // Ampelschaltung
if ((millis() - ampelMillis >= ampelIntervall)&& (valueAN == HIGH)) {
switch (zustand) {
case ZUSTAND1:
if (valueAN != true) break;
digitalWrite(GELBPin, HIGH);
digitalWrite(GRUENPin, LOW);
digitalWrite(BLAUPin, LOW);
zustand = ZUSTAND2;
ampelMillis = millis();
ampelIntervall = ZEITBEWAESSERUNG * 10;
break;
case ZUSTAND2:
if (valueAN != HIGH) break;
digitalWrite(GELBPin, LOW);
digitalWrite(GRUENPin, LOW);
digitalWrite(BLAUPin, LOW);
zustand = ZUSTAND3;
ampelMillis = millis();
ampelIntervall = ZEITBEWAESSERUNG * 10;
break;
case ZUSTAND3:
if (valueAN != HIGH) break;
digitalWrite(GELBPin, LOW);
digitalWrite(GRUENPin, HIGH);
digitalWrite(BLAUPin, LOW);
zustand = ZUSTAND4;
ampelMillis = millis();
ampelIntervall = ZEITBEWAESSERUNG * 10;
break;
case ZUSTAND4:
if (valueAN != HIGH) break;
digitalWrite(GELBPin, LOW);
digitalWrite(GRUENPin, LOW);
digitalWrite(BLAUPin, LOW);
zustand = ZUSTAND5;
ampelMillis = millis();
ampelIntervall = ZEITBEWAESSERUNG * 10;
break;
case ZUSTAND5:
if (valueAN != HIGH) break;
digitalWrite(GELBPin, LOW);
digitalWrite(GRUENPin, LOW);
digitalWrite(BLAUPin, HIGH);
zustand = PAUSE;
ampelMillis = millis();
ampelIntervall = ZEITBEWAESSERUNG * 10;
break;
case PAUSE:
if (valueAN != HIGH) break;
digitalWrite(GELBPin, LOW);
digitalWrite(GRUENPin, LOW);
digitalWrite(BLAUPin, LOW);
zustand = ZUSTAND1;
ampelMillis = millis();
ampelIntervall = ZEITPAUSE * 100; // in Millis
//ampelIntervall = ZEITPAUSE * 60000; //in Minute
break;
}
}
}
void setup()
{
Serial.begin(115200); // See the connection status in Serial Monitor
Blynk.begin(************************); //RASPI CONF IP Adresse local server
WiFi.hostname("Intervall_Test_1");
// Definiert die Pins als Ausgang
pinMode(GELBPin, OUTPUT);
pinMode(GRUENPin, OUTPUT);
pinMode(BLAUPin, OUTPUT);
rtc.begin();
timer.setInterval(100L, Ventile);
}
void loop()
{
Blynk.run();
timer.run(); // Initiates SimpleTimer to ensure the 60s timer keeps running
}