pdf-icon

Arduino Quick Start

2. Devices & Examples

6. Applications

Dial Button

APIs and example programs related to Dial button input.

Button Position
The button is located at the bottom of the product, below the M5 logo. Pressing down on the gray border will trigger it.

Example Program

Build Requirements

  • M5Stack board manager version >= 3.2.2
  • Board option = M5Dial
  • M5Dial library version >= 1.0.3
Notes
When using the button, you need to include the M5Dial.update() function in the main loop to read status updates. Try to minimize blocking operations; otherwise, button state changes may not be detected in time.
cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include "M5Dial.h"

void setup() {
  auto cfg = M5.config();
  M5Dial.begin(cfg, false, false);  // encoder, RFID
  Serial.begin(115200);
}

void loop() {
  M5Dial.update();

  if (M5Dial.BtnA.wasPressed()) {
    Serial.println("Button A Pressed");
  }
  if (M5Dial.BtnA.wasReleased()) {
    Serial.println("Button A Released");
  }
}

API

The M5Dial library is built on top of the M5Unified library. The button driver uses the Button_Class provided by M5Unified. For more related APIs, please refer to the following document:

On This Page