pdf-icon

Button

M5StickC Plus2 keystroke input related APIs and case programs.

Note:
Include StickCP2.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 "M5StickCPlus2.h"

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

void loop() {
    StickCP2.update();
    if (StickCP2.BtnA.wasPressed()) {
        Serial.println("A Btn Pressed");
    }
    if (StickCP2.BtnA.wasReleased()) {

        Serial.println("A Btn Released");
    }
    if (StickCP2.BtnB.wasPressed()) {
        Serial.println("B Btn Pressed");
    }
    if (StickCP2.BtnB.wasReleased()) {
        Serial.println("B Btn Released");
    }
}

API

M5StickC Plus2 library is based on the M5Unified library, the key part uses the Button_Class in the M5Unified library, for more key related APIs you can refer to the following document:

On This Page