// Neuer Pumpentester Heiko Piepenburg 12.02.2024 //
#include <TM1637TinyDisplay.h>
#define CLK1 9
#define DIO1 10
#define CLK2 11
#define DIO2 12
TM1637TinyDisplay display1 = TM1637TinyDisplay(CLK1, DIO1);
TM1637TinyDisplay display2 = TM1637TinyDisplay(CLK2, DIO2);
const uint8_t done[] = {
SEG_B | SEG_C | SEG_D | SEG_E | SEG_G, // d
SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F, // O
SEG_C | SEG_E | SEG_G, // n
SEG_A | SEG_D | SEG_E | SEG_F | SEG_G // E
};
// an array that sets individual segments per digit to display the word "----"
const uint8_t pause[] = {
SEG_G, // -
SEG_G, // -
SEG_G, // -
SEG_G, // -
};
// an array that sets individual segments per digit to display the word "P"
const uint8_t P[] = {
SEG_A | SEG_B | SEG_E | SEG_F | SEG_G, // P
};
bool taster0read = false; // Variable für Taster drücken (false oder true)
bool taster0on = false; // Variable für Taster AN / Aus(false oder true)
bool taster0longread = false;
bool taster0longOn = false;
bool switch0 = false; // Variable für Relais (false oder true)
bool switch1 = false;
bool blinker0 = false;
bool zustand0on = false;
bool relais0on = false;
bool wahl0schalter = false; // schalter für + 10 minuten oder normaler modus
bool wahl0ist = false; // false normal - true mit 10 minuten
unsigned long timer0millis = 0; // Timer auf 0
unsigned long taster0millis = 0; // Taster entprellen millis auf 0
unsigned long blinker0millis = 0; // Blinker millis auf 0
unsigned long sekunde1millis = 0;
unsigned long timer = 0;
unsigned long counter0 = 0;
unsigned long zaehler = 0;
unsigned long switch1millis = 0;
unsigned int pumpen = 16; // Pumpzeit in Sekunden
unsigned int warten = 30; //Wartezeit in Sekunden
unsigned int anzahl = 1000; // Anzahl der Wiederholungen
void setup() {
display1.clear();
display1.setBrightness(4); // set the brightness to 5 (0:dimmest, 7:brightest)
display2.setBrightness(2);
pinMode(3, INPUT_PULLUP); //Taster auf Pin 3 mit Pullup Widerstand
pinMode(7, OUTPUT); // LED rot
pinMode(13, OUTPUT); // Relais
pinMode(6, INPUT_PULLUP); //Schalter 1000 x 16 Sek
pinMode(5, INPUT_PULLUP); // Schalter 10 Min +
pinMode (8, OUTPUT);
display1.setSegments(pause);
} // ende void setup
void loop() {
wahl0schalter = digitalRead(6);
if(wahl0schalter == true){
wahl0ist = wahl0schalter;
}else{wahl0ist=false;
}
if (wahl0ist == true&&timer==0&&counter0==0){
digitalWrite(8,true);
display2.setSegments(pause);
}else{
digitalWrite(8,false);
}
Taster ();
LED ();
Counter ();
Relay ();
if (switch0 == true && switch1 == false && zustand0on == false) {
display1.showNumberDec(timer);
} else {
} // end switch0 true
if (switch1 == true&&wahl0ist==false) {
display2.setSegments(done);
zustand0on = false;
zaehler = 0;
} else {
if(wahl0ist==true){
display2.setSegments(pause);
}else{display2.showNumberDec(zaehler);}
display2.showNumberDec(zaehler);
}
} //ende void loop
void Counter(){
if (zaehler >= anzahl) { // bei erreichen der Anzahl der Wiederholungen reseten
zustand0on = false;
taster0longOn = false;
switch0 = false;
relais0on = false;
timer=0;
counter0=0;
zaehler=0;
display2.setSegments(done);
display1.setSegments(done);
}
if (millis() - sekunde1millis > 1000 && switch0 == true && zustand0on == true) {
counter0 = counter0 - 1;
sekunde1millis = millis();
}
if (zustand0on == true && counter0 > 0) {
display1.showNumberDec(counter0);
}
if (counter0 <= 0) {
zustand0on = false;
}
} // end void Counter
void Timer(){
if (timer > pumpen && anzahl >= zaehler) {
zaehler = zaehler + 1;
timer = 0;
zustand0on = true;
counter0 = warten;
display1.showNumberDec(counter0);
}
} // end void Timer
void Taster(){
taster0read = digitalRead(3); // abfrage Taster Pin 3
if (millis() - sekunde1millis > 1000 && switch0 == true && zustand0on == false) {
timer = timer + 1;
sekunde1millis = millis();
}
if (taster0read == true) { // entprellen vom taster
taster0millis = millis();
} //ende von If taster0 - millis
if (taster0read == false && taster0longOn == false && millis() - taster0millis > 500) {
taster0longOn = true;
} //end taster > 1000
if (taster0read == false && taster0on == false && millis() - taster0millis > 20 && taster0longOn == false) {
taster0on = true;
} //ende if Taster false
if (taster0read == true && taster0on == true) {
taster0on = false;
switch0 = !switch0; // beim loslassen vom Taster wird der zustand vom relais gewechselt
} //ende If Taster true
if (taster0read == true && taster0longOn == true) {
taster0longOn = false;
switch1 = !switch1; // beim loslassen vom Taster wird der zustand vom relais gewechselt
switch1millis = millis();
} //ende If Taster true
}// end Void Taster
void LED(){
if (millis() - switch1millis > 500) {
switch1 = false;
}
if (switch1 == true) {
digitalWrite(8, true);
digitalWrite(7, false);
timer = 0;
display1.setSegments(pause);
switch0 = false;
} else {
digitalWrite(8, false);
}
if (switch0 == true && switch1 == false) { // LED wird geschaltet
digitalWrite(7, true);
} //ende If switch0 == true
else {
digitalWrite(7, false);
} //end else
} // end void LED
void Relay(){
if (switch0 == true && zustand0on == false) {
relais0on = true;
} else {
relais0on = false;
}
if (relais0on == true) {
digitalWrite(13, true);
} else {
digitalWrite(13, false);
}
} // end void Relay