
Arduino Quick Start
API and example programs for StackChan button input functionality.
M5.update() function in the main loop to read state updates, and minimize blocking operations as much as possible. Otherwise, button state changes may not be captured in a timely manner.#include <M5Unified.h>
void setup(void)
{
auto cfg = M5.config();
M5.begin(cfg);
M5.Display.setTextColor(RED);
M5.Display.setTextDatum(middle_center);
M5.Display.setFont(&fonts::Orbitron_Light_24);
M5.Display.setTextSize(1);
M5.Display.drawString("Touch Button Test", M5.Display.width() / 2, 15);
}
void loop(void)
{
M5.update();
if (M5.BtnPWR.wasClicked()) {
M5.Display.fillRect(0, 40, M5.Display.width(), 70, BLACK);
M5.Display.drawString("Btn PWR", M5.Display.width() / 2, M5.Display.height() / 2 - 30);
}
}After flashing successfully, you can trigger an event by pressing the StackChan power button (BtnPWR). When you click the button, the device will detect the event and display the text "Btn PWR" on the screen.
The physical button (BtnPWR) state reading on StackChan relies on the power management chip. Currently, only wasClicked and wasHold are available for normal use.