pdf-icon

Arduino Quick Start

2. Devices & Examples

Basic/Gray/M5GO Button

Basic/Gray/M5GO button input related APIs and example program.

Note:
Include M5.update() function in the main loop to read status update and minimize blocking, otherwise you may not to be able to retrieve the status of key changes in time.

Example

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#include "M5Unified.h"

void setup()
{
    auto cfg = M5.config();
    M5.begin(cfg);
    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");
    }
}

For actual implementation results, download the example program, press the buttons, and open the serial monitor to see the output.

API

The button part of Basic/Gray/M5GO uses the Button_Class in the M5Unified library. For more APIs related to buttons, you can refer to the document below:

On This Page