#include <Toggle.h>
const byte pinLeds[] = {8, 6, 4, 2};
const char * couleurs[] = {"vert", "rouge", "bleu", "jaune"};
const byte nbElements = sizeof pinLeds / sizeof * pinLeds;
Toggle boutonGo {A0};
void eteindre() {
for (byte i = 0; i < nbElements; i++) digitalWrite(pinLeds[i], LOW);
}
void animationDebut() {
int8_t ledEnCours = 0;
int8_t increment = +1;
unsigned long chrono = 0;
while (true) {
boutonGo.poll();
if (boutonGo.onPress()) Serial.println(F("Go !"));
if (boutonGo.onRelease()) break;
if (millis() - chrono >= 250) {
digitalWrite(pinLeds[ledEnCours], (increment > 0) ? HIGH : LOW);
ledEnCours += increment;
if (ledEnCours >= nbElements) {
ledEnCours = nbElements - 1;
increment = -increment;
} else if (ledEnCours < 0) {
ledEnCours = 0;
increment = -increment;
}
chrono = millis();
}
}
eteindre();
Serial.println(F("c'est le moment du décomte !"));
}
void setup() {
for (byte i = 0; i < nbElements; i++) pinMode(pinLeds[i], OUTPUT);
Serial.begin(115200);
Serial.println(F("Appuyez sur GO pour commencer"));
animationDebut(); // appel bloquant en attente du relâchement du bouton GO
}
void loop() {}
GO !!