#define STATUS 0
#define STOP 1
#define START 2
#define UPDATE 3
#define STOPPED 0
#define RUNNING 1
#define TIMEOUT 2
const byte VentilStellZeit=6;
int button_start_Pin = 8; // push button is connected
int button_stop_Pin = 7; // push button is connected
int temp = 0; // temporary variable for reading the button pin status
int button_start_State = 0;
int button_stop_State = 0;
void setup() {
Serial.begin(115200); //seriellen Monitor aktivieren
Serial.println(F("Start..."));
delay(100);
//Serial.printf("\nSketchname: %s\nBuild: %s\t\tIDE: %d.%d.%d\n%s\n\n",
// (__FILE__), (__TIMESTAMP__), ARDUINO / 10000, ARDUINO % 10000 / 100, ARDUINO % 100 / 10 ? ARDUINO % 100 : ARDUINO % 10, ESP.getFullVersion().c_str());
pinMode(button_start_Pin, INPUT);
pinMode(button_start_Pin, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
valve_timer(UPDATE);
button_start_State = digitalRead(button_start_Pin);
button_stop_State = digitalRead(button_stop_Pin);
//Serial.print(button_start_State);
//Serial.println(button_stop_State);
if (button_start_State==LOW) valve_timer(START);
if (button_stop_State==LOW) valve_timer(STOP);
}
byte valve_timer(byte timer_action){
static unsigned long startmillis= 0;
static byte valve_timer_status=STOPPED;
if (timer_action==START&&valve_timer_status!=RUNNING){
startmillis=millis();
valve_timer_status=RUNNING;
Serial.println("Ventiltimer gestartet");
}
else if (timer_action==STOP&&valve_timer_status!=STOPPED){
valve_timer_status=STOPPED;
Serial.println("Ventiltimer gestoppt");
}
else if (timer_action==UPDATE&&valve_timer_status==RUNNING){
if (millis()-startmillis > VentilStellZeit*1000){
valve_timer_status=TIMEOUT;
Serial.println("Ventiltimer abgelaufen");
}
}
//else if (timer_action==STATUS){
return valve_timer_status;
}