// Définir les broches pour les 12 relais
const int relayPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
const int numRelays = sizeof(relayPins) / sizeof(relayPins[0]);
// Définir l'animation des LEDs pour chaque étape
const int animation[][12] = {
{HIGH, LOW, LOW, LOW, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH},
{LOW, HIGH, LOW, LOW, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH},
{LOW, LOW, HIGH, LOW, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH},
{LOW, LOW, LOW, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH},
{HIGH, LOW, LOW, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH},
{LOW, HIGH, LOW, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH},
{LOW, LOW, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH},
{HIGH, LOW, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH},
{LOW, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH},
{LOW, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH},
{LOW, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH},
{LOW, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH},
{LOW, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH},
{LOW, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH},
{LOW, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH},
{LOW, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH}
};
const int numSteps = sizeof(animation) / sizeof(animation[0]);
const int potPin = A0; // Broche du potentiomètre
const int buttonPin = 18; // Broche du bouton
bool buttonPressed = false;
bool wasButtonPressed = false;
void setup() {
// Initialiser les broches des relais comme sorties
for (int i = 0; i < numRelays; i++) {
pinMode(relayPins[i], OUTPUT);
}
// Configurer la broche du bouton en entrée avec une résistance de pull-up
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
// Lire la valeur du bouton
buttonPressed = digitalRead(buttonPin) == LOW;
// Vérifier si le bouton est pressé
if (buttonPressed && !wasButtonPressed) {
// Déclencher l'animation seulement si le bouton vient d'être pressé
startAnimation();
} else if (!buttonPressed && wasButtonPressed) {
// Arrêter l'animation seulement si le bouton vient d'être relâché
stopAnimation();
}
// Mettre à jour l'état du bouton pour la prochaine itération
wasButtonPressed = buttonPressed;
}
// Fonction pour démarrer l'animation
void startAnimation() {
int potValue = analogRead(potPin);
int animationDelay = map(potValue, 0, 1023, 50, 1000);
// Boucle à travers chaque étape de l'animation
for (int step = 0; step < numSteps; step++) {
// Appliquer les états des LEDs pour l'étape actuelle
for (int relay = 0; relay < numRelays; relay++) {
digitalWrite(relayPins[relay], animation[step][relay]);
}
// Attendre le délai calculé avant de passer à l'étape suivante
delay(animationDelay);
}
}
// Fonction pour arrêter l'animation
void stopAnimation() {
// Mettre toutes les broches des relais à LOW pour éteindre les LEDs
for (int i = 0; i < numRelays; i++) {
digitalWrite(relayPins[i], LOW);
}
}