
Arduino Quick Start
Button input APIs and example for AtomS3U.
M5.update() in your main loop to refresh button states and avoid long blocking operations so button events are captured reliably.#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 AtomS3U button support uses the Button_Class from the M5Unified library. See the documentation for more APIs: