const int buttonPins[] = {2, 3, 4}; // Les pins des boutons
const int Led[] = {5, 6, 7, 8}; // Pins Led
const int relayPin = 9; // Le pin du relais
const int sequence[] = {0, 1, 0, 2, 0, 2}; // Séquence à suivre
const int sequenceLength = sizeof(sequence) / sizeof(sequence[0]);
int currentStep = 0;
void setup() {
for (int i = 0; i < 4; i++) {
pinMode(buttonPins[i], INPUT_PULLUP);
}
for (int j = 0; j < 4; j++){
pinMode(Led[j], OUTPUT);
digitalWrite(Led[j], LOW);
}
Serial.begin(9600);
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW); // Assurez-vous que le relais est désactivé au début
}
void loop() {
for (int i = 0; i < 5; i++) {
if (digitalRead(buttonPins[i]) == HIGH) {
Serial.print("bouton");
Serial.print(i);
digitalWrite(Led[i], HIGH);
if (i == sequence[currentStep]) {
currentStep++;
delay(200); // Anti-rebond
digitalWrite(Led[i], LOW);
while (digitalRead(buttonPins[i]) == HIGH); // Attendez que le bouton soit relâché
} else {
currentStep = 0; // Réinitialiser la séquence si le mauvais bouton est pressé
}
}
}
if (currentStep == sequenceLength) {
digitalWrite(relayPin, HIGH); // Activer le relais
delay(5000); // Maintenir le relais activé pendant 5 secondes (par exemple)
digitalWrite(relayPin, LOW); // Désactiver le relais
currentStep = 0; // Réinitialiser la séquence
}
}