pdf-icon

Arduino Quick Start

StickC-Plus2 Button

StickC-Plus2 Button 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

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
#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");
}
if (StickCP2.BtnPWR.wasClicked()) {
Serial.println("PWR Btn Clicked");
}
if (StickCP2.BtnPWR.wasHold()) {
Serial.println("PWR Btn Hold");
}
}

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:

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

On This Page