
Arduino Quick Start
APIs and sample sketch for button input on Unit PoE-P4.
M5.update() in the main loop to refresh the state, and avoid long blocking delays so that events are detected promptly.#include "M5Unified.h"
void setup() {
M5.begin();
Serial.begin(115200);
}
void loop() {
M5.update();
if (M5.BtnA.wasPressed()) {
Serial.println("BtnA was pressed");
}
if (M5.BtnA.wasReleased()) {
Serial.println("BtnA was released");
}
if (M5.BtnA.wasSingleClicked()) {
Serial.println("BtnA was single clicked");
}
if (M5.BtnA.wasDoubleClicked()) {
Serial.println("BtnA was double clicked");
}
if (M5.BtnA.wasHold()) {
Serial.println("BtnA was held");
}
}This sketch monitors the front button and prints messages to the serial monitor when it is pressed, released, clicked (single/double) or held. Example output:
BtnA was pressed
BtnA was released
BtnA was single clicked
BtnA was pressed
BtnA was held
BtnA was released The Unit PoE-P4 button uses Button_Class from the M5Unified library. See the documentation for more details: