const byte P1=13; // normal pump
const byte P2=12; // extra pump after 30 sec
int simulateLevel (bool p1, bool p2) {
// p1 reduces by 4/sec
// p1 & p2 reduces by 12/sec
// both false increases by 15/sec
// random by (-10...10)/sec
int x = -10 + random(21);
if (!p1 && !p2) x +=15;
if ( p1 ) x -=4;
if ( p2 ) x -=8;
return x;
}
void setup() {
pinMode(P1, OUTPUT);
pinMode(P2, OUTPUT);
Serial.begin(115200);
}
unsigned int level=800;
bool p1, p2;
unsigned long runTime;
const unsigned int HI = 900; // switch on
const unsigned int LO = 800; // switch off
const unsigned long BOOST = 30000; // switch extra pump on after BOOST msec
void loop() {
Serial.print("775, 925, 900, 800, "); Serial.print(level);
Serial.print(","); Serial.println(digitalRead(13) ? 899 : 801);
if (level > HI) {
if (p1==false) runTime= millis();
p1 = true;
}
if (p1 && millis() - runTime > BOOST) {
p2 = true;
}
if (level < LO) {
p1 = false;
p2 = false;
}
digitalWrite(P1, p1);
digitalWrite(P2, p2);
level += simulateLevel(p1, p2);
delay(250);
}