gpio_led_button_control.ino

M5Stack PaperDIY Complete Kit ESP32-S3 e-paper Development Kit · File : gpio_led_button_control.ino · Language : C++ (Arduino) · Use case : Contrôler une LED externe via un bouton poussoir connecté aux GPIOs.

Basic GPIO interaction example with a button and an LED.

Requires an external LED with a current-limiting resistor on GPIO 4 and a button on GPIO 0. Compile using the 'M5Stack-Cardputer' or 'ESP32-S3 Dev Module' board in the Arduino IDE. Upload the code and press the button to light the LED.

gpio_led_button_control.ino

#include <Arduino.h>

// Broches spécifiques au M5Stack PaperDIY (à vérifier selon le schéma final, ici broches génériques ESP32-S3)
const int BUTTON_PIN = 0; // Bouton BOOT ou GPIO dédié
const int LED_PIN = 4;    // GPIO libre pour LED externe

void setup() {
  Serial.begin(115200);
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, LOW);
  Serial.println("M5Stack PaperDIY GPIO Test");
}

void loop() {
  // Lecture du bouton (actif à LOW avec pull-up)
  if (digitalRead(BUTTON_PIN) == LOW) {
    digitalWrite(LED_PIN, HIGH);
    Serial.println("Button Pressed");
    delay(200); // Anti-rebond simple
  } else {
    digitalWrite(LED_PIN, LOW);
  }
}

← Back to the board