Bonjour ,
Je cherche à faire un programme qui allume une led quand j'appuie sur un bouton poussoir et quand je rappuie sur ce bouton poussoir la led s'éteint.
J'ai essayé d'adapter le programme donné sur le site arduino (read a pushbutton, filtering noise http://arduino.cc/en/Tutorial/Debounce) mais mon code ne marche pas et je ne trouve pas mon erreur.
const int buttonPin = 30; // the number of the pushbutton pin
const int ledPin = 40; // the number of the LED pin
int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin
long lastDebounceTime = 0;
long debounceDelay = 200;
int a=0;
void setup() {
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
int reading = digitalRead(buttonPin);
if (reading != lastButtonState && reading == HIGH ) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay ) {
buttonState = reading;
}
if(buttonState==HIGH ){
if (a==0) {digitalWrite(ledPin, HIGH); a=1;
Serial.println("High");
}
else {digitalWrite(ledPin, LOW); a=0;
Serial.println("Low");}
}
lastButtonState = reading;
}