pdf-icon

Arduino Quick Start

2. Devices & Examples

6. Applications

Arduino Nesso N1 Button

Arduino Nesso N1 button input-related API and example program.

Notes:
When in use, make sure to include the M5.update() function in the main loop to read status updates and minimize blocking as much as possible, otherwise button state changes may not be captured in time.

Example Program

Compilation Requirements

  • M5Stack board manager version >= 3.2.5
  • Board option = ArduinoNessoN1
  • M5GFX library version >= 0.2.17
  • M5Unified 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 21 22 23 24 25
#include "M5Unified.h"

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

void loop()
{
    M5.update();
    if (M5.BtnA.wasPressed()) {
        Serial.println("A Btn Pressed");
    }
    if (M5.BtnA.wasReleased()) {
        Serial.println("A Btn Released");
    }
    if (M5.BtnB.wasPressed()) {
        Serial.println("B Btn Pressed");
    }
    if (M5.BtnB.wasReleased()) {
        Serial.println("B Btn Released");
    }
}

API

The button driver of Arduino Nesso N1 uses the Button_Class in the M5Unified library. For more button-related APIs, please refer to the following document:

On This Page