pdf-icon

Arduino Quick Start

2. Devices & Examples

Air Quality Button

Air Quality button input related APIs and example program.

Example

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#include <M5Unified.h>

void setup() {
  
  auto cfg = M5.config(); 
  cfg.serial_baudrate = 115200;
  M5.begin(cfg);

  M5.Lcd.clear();
  M5.Lcd.setTextSize(2);
  M5.Lcd.setCursor(0, 0);
  M5.Lcd.println("M5AirQ Button Test");
}

void loop() {
  M5.update();           

  // Detect BtnA (GPIO0) click
  if (M5.BtnA.wasClicked()) {
    Serial.println("AirQ BtnA clicked");
    M5.Lcd.println("BtnA clicked");
  }

  // Detect BtnB (GPIO8) click
  if (M5.BtnB.wasClicked()) {
    Serial.println("AirQ BtnB clicked");
    M5.Lcd.println("BtnB clicked");
  }
  delay(10);
}

After uploading, press the buttons to see the following effect:

API

The button functionality uses the Button_Class from the M5Unified library. For more button-related APIs, please refer to the documentation below:

On This Page