#define LED_PIN 2 // LED sur GPIO 7
#define BUTTON_PIN 4 // Bouton sur GPIO 5
void setup() {
pinMode(LED_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT_PULLUP); // Active la résistance interne de pull-up
Serial.begin(115200);
Serial.println("Appuyez sur le bouton pour allumer la LED !");
}
void loop() {
// Lit l'état du bouton (LOW quand appuyé car PULLUP)
int buttonState = digitalRead(BUTTON_PIN);
if (buttonState == LOW) { // Bouton appuyé
digitalWrite(LED_PIN, HIGH);
Serial.println("LED ALLUMÉE");
} else { // Bouton relâché
digitalWrite(LED_PIN, LOW);
Serial.println("LED ÉTEINTE");
}
delay(50); // Petite pause pour éviter les rebonds
}