#define PIN_PRE 2 // pressostat
#define PIN_RLYOPEN 10 // Activation relay ouverture robinet eau de ville
#define PIN_RLYCLOSE 11 // Activation relay fermeture robinet eau de ville
#define PIN_LEDPLUIE 9 // LED quand EAU PLUIE actif
#define PIN_LEDVILLE 8 // LED quand EAU VILLE actif
#define DelayStatus 60 // Delais de maintenance du relay (en secondes)
#define DelayCligno 300 // Delais de clignotement LED (en millisecondes)
bool Pressostat = false;
bool PressPrev = false;
bool RelayLow = false;
bool ClignoOn = false;
bool LedVilleOn = false;
bool LedVilleOnTmp = false;
bool LedPluieOn = false;
bool LedPluieOnTmp = false;
bool initPgm = true;
unsigned long TimeStatus = 0;
unsigned long TimeCligno = 0;
void setup() {
Serial.begin(9600);
pinMode(PIN_PRE, INPUT_PULLUP); // Lecture du contact du pressostat
pinMode(PIN_RLYOPEN, OUTPUT); // Activation relay Robinet OUVERT
pinMode(PIN_RLYCLOSE, OUTPUT); // Activation relay Robinet FERME
pinMode(PIN_LEDPLUIE, OUTPUT); // EAU PLUIE actif
pinMode(PIN_LEDVILLE, OUTPUT); // EAU VILLE actif
}
void loop() {
if (((millis() - TimeStatus) / 1000) > DelayStatus or initPgm == true)
{
PressPrev = Pressostat;
Pressostat = !digitalRead(PIN_PRE); // connaître l'état du pressostat (PULLUP, j'inverse le status)
// Init de l'Arduino => on force le robinet dans la position correspodant au Pressostat
if (initPgm == true) {
PressPrev = !Pressostat;
initPgm = false;
}
// changement d'etat du pressostat
if (PressPrev != Pressostat)
{
Serial.println("Changement etat pressostat");
if (Pressostat == HIGH) {
//EAU DE PLUIE SOUS PRESSION
ClignoOn = true;
LedPluieOn = true;
LedVilleOn = false;
digitalWrite(PIN_LEDVILLE, LOW); // Eteindre LED EAU VILLE
Serial.println("EAU DE PLUIE SOUS PRESSION");
TimeStatus = millis();
RelayLow = false;
digitalWrite(PIN_RLYOPEN, LOW);
digitalWrite(PIN_RLYCLOSE, HIGH);
delay(500);
}
else
{
// BAISSE DE PRESSION DE L'EAU DE PLUIE
Serial.println("BAISSE DE PRESSION DE L'EAU DE PLUIE");
ClignoOn = true;
LedVilleOn = true;
LedPluieOn = false;
digitalWrite(PIN_LEDPLUIE, LOW); // Eteindre LED EAU PLUIE
TimeStatus = millis();
RelayLow = false;
digitalWrite(PIN_RLYOPEN, HIGH);
digitalWrite(PIN_RLYCLOSE, LOW);
delay(500);
}
} // fin changement d'etat du pressostat
// Si delai depassé, je coupe l'alim des 2 relay
if (((millis() - TimeStatus) / 1000) > DelayStatus and RelayLow != true)
{
Serial.println("Arret des 2 relais.");
ClignoOn = false;
digitalWrite(PIN_RLYOPEN, LOW);
digitalWrite(PIN_RLYCLOSE, LOW);
RelayLow = true;
delay(500);
}
} // fin timer
// LED eau de ville (et clignotement durant l'action du robinet)
if ( LedVilleOn == true) {
if (ClignoOn == true) {
if (millis() - TimeCligno > DelayCligno) {
TimeCligno = millis();
LedVilleOnTmp = ! LedVilleOnTmp;
digitalWrite(PIN_LEDVILLE, LedVilleOnTmp); // Allumer LED EAU VILLE
}
}
else {
digitalWrite(PIN_LEDVILLE, HIGH); // Allumer LED EAU VILLE
}
}
// LED eau de pluie (et clignotement durant l'action du robinet)
if (LedPluieOn == true) {
if (ClignoOn == true) {
if (millis() - TimeCligno > DelayCligno) {
TimeCligno = millis();
LedPluieOnTmp = ! LedPluieOnTmp;
digitalWrite(PIN_LEDPLUIE, LedPluieOnTmp); // Allumer LED EAU PLUIE
}
}
else {
digitalWrite(PIN_LEDPLUIE, HIGH); // Allumer LED EAU PLUIE
}
}
} // Fin loop