
Arduino Quick Start
APIs and example programs for Cardputer button input, applicable to both Cardputer and Cardputer-Adv.
M5Cardputer.update() function in the main loop to read state updates. Try to minimize blocking operations; otherwise, button state changes may not be detected in time.#include "M5Cardputer.h"
void setup() {
auto cfg = M5.config();
M5Cardputer.begin(cfg);
Serial.begin(115200);
}
void loop() {
M5Cardputer.update();
if (M5Cardputer.BtnA.wasPressed()) {
Serial.println("Button A Pressed");
}
if (M5Cardputer.BtnA.wasReleased()) {
Serial.println("Button A Released");
}
}The M5Cardputer library is built on top of the M5Unified library. The Button function uses the Button_Class from the M5Unified library. For more related APIs, please refer to the following documentation: