English
English
简体中文
日本語
pdf-icon

Arduino Quick Start

2. Devices & Examples

5. Extensions

6. Applications

CoreS3 Button

CoreS3 button input related APIs and example programs.

Note:
When using, you need to include the M5.update() function in the main loop for reading state updates and minimize blocking situations as much as possible, otherwise the button state changes may not be obtained in time.

Example Program

Compilation Requirements

  • M5Stack Board Manager version >= 3.2.2
  • Board selection = M5CoreS3
  • M5Unified library version >= 0.2.11
  • M5GFX library version >= 0.2.18
cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#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 successful upload, you can trigger events by pressing the CoreS3 power button (BtnPWR). When the button is clicked, the device will detect this event and display the text "Btn PWR" on the screen.

API

The physical button (BtnPWR) state reading of CoreS3 depends on the power management chip. Currently only wasClicked and wasHold are available for normal use.

On This Page