const byte pinPotentiometre = A0;
const int pinConsigne = 12;
const unsigned long dureeCycle = 4000;
unsigned long debut;
bool actif = false;
void allumer() {
digitalWrite (pinConsigne, HIGH);
debut = millis();
actif = true;
}
void eteindre() {
Serial.print("J'éteins. J'étais allumé pendant (ms) : ");
Serial.println(millis() - debut);
digitalWrite (pinConsigne, LOW);
actif = false;
}
void setup () {
Serial.begin(115200);
pinMode(pinConsigne, OUTPUT);
}
void loop() {
if (actif) {
int reglagePotar = analogRead(pinPotentiometre);
unsigned long tpsConduction = map(reglagePotar, 0, 1023, 0, 1000);
if (millis() - debut >= tpsConduction) eteindre();
} else {
if (millis() - debut >= dureeCycle) allumer();
}
}