pdf-icon

Arduino Guide

Button

CoreS3 button input related APIs and case programs.

Note:
Include CoreS3.update() function in the main loop to read status update and minimize blocking, otherwise you may not be able to retrieve the status of key changes in time.

Example

#include <M5CoreS3.h>

void setup(void)
{
    auto cfg = M5.config();
    CoreS3.begin(cfg);

    CoreS3.Display.setTextColor(RED);
    CoreS3.Display.setTextDatum(middle_center);
    CoreS3.Display.setFont(&fonts::Orbitron_Light_24);
    CoreS3.Display.setTextSize(1);
    CoreS3.Display.drawString("Touch Button Test", CoreS3.Display.width() / 2, 15);
}

void loop(void)
{
    CoreS3.update();

    if (CoreS3.BtnPWR.wasClicked()) {
        CoreS3.Display.fillRect(0, 40, CoreS3.Display.width(), 70, BLACK);
        CoreS3.Display.drawString("Btn PWR", CoreS3.Display.width() / 2, CoreS3.Display.height() / 2 - 30);
    }
}

API

The status reading of the physical button (BtnPWR) on CoreS3 depends on the power management chip. Currently, only "wasClicked" and "wasHold" can be used normally.

On This Page