pdf-icon

Arduino Quick Start

2. Devices & Examples

5. Extensions

6. Applications

AtomS3U Button

Button input APIs and example for AtomS3U.

Note
Include M5.update() in your main loop to refresh button states and avoid long blocking operations so button events are captured reliably.

Example

Compilation Requirements

  • M5Stack Board Manager version >= 3.2.6
  • Development board option = M5AtomS3
  • M5Unified library version >= 0.2.13
cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#include "M5Unified.h"

void setup() {
    M5.begin();
    Serial.begin(115200);
}

void loop() {
    M5.update();

    if (M5.BtnA.wasPressed()) {
        Serial.println("BtnA was pressed");
    }
    if (M5.BtnA.wasReleased()) {
        Serial.println("BtnA was released");
    }
    if (M5.BtnA.wasSingleClicked()) {
        Serial.println("BtnA was single clicked");
    }
    if (M5.BtnA.wasDoubleClicked()) {
        Serial.println("BtnA was double clicked");
    }
    if (M5.BtnA.wasHold()) {
        Serial.println("BtnA was held");
    }
}

This sketch monitors the front button and prints events to the serial monitor, for example:

BtnA was pressed
BtnA was released
BtnA was single clicked
BtnA was pressed
BtnA was held
BtnA was released

API

AtomS3U button support uses the Button_Class from the M5Unified library. See the documentation for more APIs:

On This Page