gpio-button-led.ino

M5Stack PaperDIY Complete Kit ESP32-S3 e-paper Development Kit · File : gpio-button-led.ino · Language : C++ (Arduino) · Use case : Contrôler une LED et lire un bouton poussoir via les GPIO de l'ESP32-S3.

Basic example to interact with digital I/O.

Uses GPIO0 as input (button) and GPIO2 as output (LED). The ESP32-S3 handles hardware interrupts if needed. Compile with 'M5Stack-ESP32-S3' board in Arduino IDE.

gpio-button-led.ino

#include <Arduino.h>

// Définir les broches (adapter selon le schéma PaperDIY si nécessaire)
#define BUTTON_PIN 0   // Bouton BOOT intégré ou GPIO externe
#define LED_PIN 2      // LED RGB ou LED externe sur GPIO2

void setup() {
  Serial.begin(115200);
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, LOW);
}

void loop() {
  if (digitalRead(BUTTON_PIN) == LOW) {
    digitalWrite(LED_PIN, HIGH);
    Serial.println("Bouton pressé");
    delay(500);
    digitalWrite(LED_PIN, LOW);
  }
}

← Back to the board