pdf-icon

Arduino Quick Start

2. Devices & Examples

6. Applications

Fire Button

APIs and sample programs for Fire button input.

Note
When using this feature, you must include the 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.

Sample Program

Compilation Requirements

  • M5Stack Board Manager version >= 3.2.2
  • Board option = M5Fire
  • M5Unified library version >= 0.2.8
  • M5GFX library version >= 0.2.11
cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#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:

API

The Fire Button uses the Button_Class from the M5Unified library. For more related APIs, please refer to the following documentation:

On This Page