Bonjour,
je suis nouveau dans la programmation de cartes arduino et je voudrais allumer des LED pendant 2 secondes chacune de facon successive. jusque là tout va bien. mais en plus je veux rajouter un pushbotton au circuit. quand j'appuis 1 foi je demarre la sequence et je l'arrete en appuyant une foi de plus. je ne veux pas que ca marche quand c'est HIGH et que ca s'arrete quand c'est LOW.
je veux que HIGH active et desactive la sequence.
je suis arrivé avec ce code mais la sequence ne s'Arrete pas et le button n'a aucun effet.
merci
const int buttonPin = 2;
int ledState = HIGH;
int buttonState;
int lastButtonState = LOW;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;
void setup() {
pinMode(buttonPin, INPUT);
pinMode(12, OUTPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(4, OUTPUT);
pinMode(1, OUTPUT);
pinMode(13, OUTPUT);
digitalWrite(13, ledState);
digitalWrite(12, ledState);
digitalWrite(8, ledState);
digitalWrite(7, ledState);
digitalWrite(4, ledState);
digitalWrite(1, ledState);
}
void loop() {
int reading = digitalRead(buttonPin);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != buttonState) {
buttonState = reading;
if (buttonState == HIGH) {
ledState = !ledState;
}
}
}
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(4, LOW);
digitalWrite(1, LOW);
delay(2000);
digitalWrite(13, LOW);
digitalWrite(12, HIGH );
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(4, LOW);
digitalWrite(1, LOW);
delay(2000);
digitalWrite(13, LOW);
digitalWrite(12,LOW);
digitalWrite(8, HIGH );
digitalWrite(7, LOW);
digitalWrite(4, LOW);
digitalWrite(1, LOW);
delay(2000);
digitalWrite(13, LOW);
digitalWrite(12,LOW );
digitalWrite(8, LOW);
digitalWrite(7, HIGH);
digitalWrite(4, LOW);
digitalWrite(1, LOW);
delay(2000);
digitalWrite(13, LOW);
digitalWrite(12,LOW );
digitalWrite(8, LOW );
digitalWrite(7, LOW);
digitalWrite(4, HIGH);
digitalWrite(1, LOW);
delay(2000);
digitalWrite(13, LOW);
digitalWrite(12,LOW );
digitalWrite(8, LOW );
digitalWrite(7, LOW);
digitalWrite(4, LOW);
digitalWrite(1, HIGH);
delay(2000);
lastButtonState = reading;
}