bonjour, voila j'ai besoin d'un programme qui en poussant sur le bouton allume une série de leds donc led1,led2 ensuit un delay puis led3 encore un delay et led4 . ensuit quand je repousse sur le bouton les leds doivent s'éteindre dans le sens inverse . j'ai déjà essayer plusieurs programmes et ce programme si est déjà pas loin du résultat sauf que je n'arrive pas a maitre un delay pour la sécance d'allumage des leds
donc toutes les leds sont on ou off et j'ai besoin que la led 1et 2 s'allument ensemble puis un delay de ... ensuit led3 puis le delay et puis led 4 pour éteindre il faut que la led 4 s'éteint puis un delay puis donc la led3 ensuite un delay puis la led1et 2 voici le programme si vous avez des idées je suis ouvert a tout tant que ça marche ![]()
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 6; // the number of the pushbutton pin
const int ledPin = 2; // the number of the LED pin
const int ledPin2= 3;
const int ledPin3= 4;
const int ledPin4= 5;
// Variables will change:
int ledState = LOW; // the current state of the output pin
int ledState2= LOW;
int ledState3= LOW;
int ledState4= LOW;
int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin
// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 10; // the debounce time; increase if the output flickers
void setup() {
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
// set initial LED state
digitalWrite(ledPin, ledState);
digitalWrite(ledPin2, ledState2);
digitalWrite(ledPin3, ledState3);
digitalWrite(ledPin4, ledState4);
}
void loop() {
// read the state of the switch into a local variable:
int reading = digitalRead(buttonPin);
// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH), and you've waited
// long enough since the last press to ignore any noise:
// If the switch changed, due to noise or pressing:
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
// if the button state has changed:
if (reading != buttonState) {
buttonState = reading;
// only toggle the LED if the new button state is HIGH
if (buttonState == HIGH) {
ledState = !ledState;
ledState2 = !ledState2;
ledState3 = !ledState3;
ledState4 = !ledState4;
}
}
}
// set the LED:
digitalWrite(ledPin, ledState);
digitalWrite(ledPin2, ledState2);
digitalWrite(ledPin3, ledState3);
digitalWrite(ledPin4, ledState4);
// save the reading. Next time through the loop,
// it'll be the lastButtonState:
lastButtonState = reading;
}