pdf-icon

Arduino入門

2. デバイス&サンプル

StamPLC Button

StamPLC button input related APIs and example program.

Note:
When using, you must include the M5.update() function in the main loop to read state updates and minimize blocking; otherwise, the button state changes may not be captured in time.

Example Program

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 27 28 29 30
#include <Arduino.h>
#include <M5Unified.h>

void setup()
{
    /* Init M5 */
    M5.begin();

    M5.Display.setTextScroll(true);
    M5.Display.setTextColor(TFT_GREENYELLOW);
    M5.Display.println("Button example");
    M5.Display.setTextColor(TFT_YELLOW);
}

void loop()
{
    /* Update button states */
    M5.update();

    /* Check if button was clicked */
    if (M5.BtnA.wasClicked()) {
        M5.Display.println("Button A was clicked");
    } else if (M5.BtnB.wasClicked()) {
        M5.Display.println("Button B was clicked");
    } else if (M5.BtnC.wasClicked()) {
        M5.Display.println("Button C was clicked");
    }

    delay(100);
}

API

The M5StamPLC library is implemented based on the M5Unified library, with the button functionality utilizing the Button_Class from M5Unified. For more button-related APIs, please refer to the documentation below:

On This Page