const byte rgbPins[] = {9, 10, 11};
struct t_couleur {
const byte r;
const byte g;
const byte b;
};
const t_couleur mesCouleurs[] = {
{255, 0, 0}, // Rouge
{0, 255, 0}, // Vert
{0, 0, 255}, // Bleu
{255, 255, 0}, // Jaune
};
const t_couleur noir = {0, 0, 0};
const int nbCouleurs = sizeof mesCouleurs / sizeof * mesCouleurs;
void afficheCouleur(const t_couleur& couleur) {
analogWrite(rgbPins[0], couleur.r);
analogWrite(rgbPins[1], couleur.g);
analogWrite(rgbPins[2], couleur.b);
}
void animation(byte nbTours, const unsigned long pause = 200) {
while (nbTours--) {
for (auto & c : mesCouleurs) {
afficheCouleur(c);
delay(pause);
}
}
}
void setup() {
Serial.begin(115200);
for (auto b : rgbPins) pinMode(b, OUTPUT);
afficheCouleur(noir); // Eteindre la LED
randomSeed(analogRead(A0));
}
void loop() {
Serial.println("animation");
animation(4);
byte indexCouleurGagnante = random(0, nbCouleurs);
Serial.print("index Couleur Gagnante = "); Serial.println(indexCouleurGagnante);
for (byte i = 0; i <= indexCouleurGagnante; i++) {
afficheCouleur(mesCouleurs[i]);
delay(1000);
}
Serial.println("terminé");
delay(6000); // pendant 3 sec
afficheCouleur(noir); // Eteindre la LED
delay(3000); // pendant 3 sec
}