
Arduino Quick Start
StopWatch button input related APIs and sample programs.
M5.update() function in the main loop to read state updates and minimize blocking as much as possible. Otherwise, button state changes may not be captured in time.#include "M5Unified.h"
void setup()
{
auto cfg = M5.config();
M5.begin(cfg);
Serial.begin(115200);
}
void loop()
{
M5.update();
if (M5.BtnA.wasPressed()) {
Serial.println("BtnA Pressed");
}
if (M5.BtnB.wasPressed()) {
Serial.println("BtnB Pressed");
}
}To see the effect, upload the example, press the buttons, and view the output in the serial monitor.
The StopWatch button section uses the Button_Class from the M5Unified library. For more button-related APIs, refer to the following document: