Skip to content

Instantly share code, notes, and snippets.

@vittodevit
Created Nov 27, 2020
Embed
What would you like to do?
Gruppo di pompe, alterna la partenza tra pompa n1 e pompa n2 alla chiusura dei contatti del pressostato.
#define PULSANTE 2 //pin del pressostato
#define POMPAUNO 7
#define POMPADUE 6
bool crun = false;
bool controlloauto = true;
int latest = 1;
void setup() {
pinMode(PULSANTE, INPUT);
pinMode(POMPAUNO, OUTPUT);
pinMode(POMPADUE, OUTPUT);
Serial.begin(115200);
}
void loop() {
if (Serial.available() > 0) {
char c = Serial.read();
switch (c) {
case '1':
digitalWrite(POMPAUNO, HIGH);
Serial.write("Accendendo pompa 1\n");
latest = 1;
crun = true;
controlloauto = false;
break;
case '2':
digitalWrite(POMPADUE, HIGH);
Serial.write("Accendendo pompa 2\n");
latest = 2;
crun = true;
controlloauto = false;
break;
case '0':
Serial.write("Spengo\n");
digitalWrite(POMPAUNO, LOW);
digitalWrite(POMPADUE, LOW);
crun = false;
controlloauto = true;
}
}
if (controlloauto == true) {
if (digitalRead(PULSANTE) == LOW) {
if (crun == false) {
if (latest == 1 ) {
digitalWrite(POMPADUE, HIGH);
Serial.write("Accendendo pompa 2\n");
latest = 2;
crun = true;
} else {
digitalWrite(POMPAUNO, HIGH);
Serial.write("Accendendo pompa 1\n");
latest = 1;
crun = true;
}
}
} else {
Serial.write("Spengo\n");
digitalWrite(POMPAUNO, LOW);
digitalWrite(POMPADUE, LOW);
crun = false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment