mpaper_gpio_button_interrupt.ino
Using GPIO interrupts to detect presses on the three physical buttons of the M5Paper.
Hardware: M5Paper with its 3 capacitive buttons (BTN0, BTN1, BTN2). Software: M5Paper.h library. Execution: Upload code, open Serial Monitor. Press buttons to see messages. Beware of hardware debouncing in interrupts.
mpaper_gpio_button_interrupt.ino
#include <M5Paper.h>
// Le M5Paper a 3 boutons physiques : BTN0 (GAUCHE), BTN1 (MILIEU), BTN2 (DROIT)
// Ils sont actifs à l'état BAS (Pull-up interne activé par défaut dans M5.begin)
void IRAM_ATTR onButtonPress() {
// Code exécuté dans l'interruption (gardez-le court)
// Ici, on pourrait simplement mettre un flag ou réveiller le processeur
}
void setup() {
M5.begin();
Serial.begin(115200);
// Configuration des broches pour les boutons
pinMode(BTN0_PIN, INPUT_PULLUP);
pinMode(BTN1_PIN, INPUT_PULLUP);
pinMode(BTN2_PIN, INPUT_PULLUP);
// Attacher les interruptions sur le front descendant (appui)
attachInterrupt(digitalPinToInterrupt(BTN0_PIN), onButtonPress, FALLING);
attachInterrupt(digitalPinToInterrupt(BTN1_PIN), onButtonPress, FALLING);
attachInterrupt(digitalPinToInterrupt(BTN2_PIN), onButtonPress, FALLING);
Serial.println("M5Paper GPIO Interrupt Example Ready");
}
void loop() {
// Vérification manuelle en complément (polling) pour debug
if (digitalRead(BTN0_PIN) == LOW) {
Serial.println("Button 0 Pressed (Polling)");
delay(200); // Anti-rebond simple
}
if (digitalRead(BTN1_PIN) == LOW) {
Serial.println("Button 1 Pressed (Polling)");
delay(200);
}
if (digitalRead(BTN2_PIN) == LOW) {
Serial.println("Button 2 Pressed (Polling)");
delay(200);
}
delay(50);
}