enum ESTADO {APAGADA, ENCENDIDA};
// variables maquina de estados
enum ESTADO estado = APAGADA;
// variables simular consumo de agua con potenciometro.
const int pin_pot = A0;
int valor_pot;
int cota_min_pot = 200;
int cota_max_pot = 900;
void setup() {
Serial.begin(9600);
pinMode(pin_pot, INPUT);
}
void loop() {
valor_pot = analogRead(pin_pot);
delay(200);
if (estado == APAGADA && valor_pot < cota_min_pot) {
estado = ENCENDIDA;
Serial.println("ENCINDIDA");
} else if (estado == ENCENDIDA && valor_pot > cota_max_pot) {
estado = APAGADA;
Serial.println("APAGADO");
} else {
Serial.print("Sin cambios en el estado: ");
Serial.println(estado);
}
}