Arduino Quick Start
APIs and sample programs for Fire button input.
M5.update()
function in the main loop to read status updates. Try to minimize blocking code, otherwise button state changes may not be captured in time.#include "M5Unified.h"
void setup() {
M5.begin();
Serial.begin(115200);
}
void loop() {
M5.update();
if (M5.BtnA.wasPressed()) {
Serial.println("BtnA Pressed");
}
if (M5.BtnB.wasPressed()) {
Serial.println("BtnB Pressed");
}
if (M5.BtnC.wasPressed()) {
Serial.println("BtnC Pressed");
}
}
The program will detect whether the three buttons are pressed and print messages in the Serial Monitor:
The Fire Button uses the Button_Class
from the M5Unified
library. For more related APIs, please refer to the following documentation: