English
English
简体中文
日本語
pdf-icon

Arduino Quick Start

2. Devices & Examples

5. Extensions

6. Applications

PaperColor Button

PaperColor button input-related APIs and example code.

Example Code

Build Requirements

  • M5Stack Board Manager version >= 3.2.7
  • Board option = M5PaperColor
  • M5Unified library version >= 0.2.15
  • M5GFX library version >= 0.2.21
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 31 32 33
#include <M5Unified.h>

static void showMessage(const char* msg)
{
    M5.Display.fillScreen(WHITE);
    M5.Display.setTextColor(BLACK);
    M5.Display.setTextFont(4);
    M5.Display.setTextSize(1);
    M5.Display.setTextDatum(middle_center);
    M5.Display.drawString(msg, M5.Display.width() / 2, M5.Display.height() / 2);
}

void setup()
{
    auto cfg          = M5.config();
    cfg.clear_display = false;
    M5.begin(cfg);
    Serial.begin(115200);
    M5.Display.setEpdMode(epd_mode_t::epd_fast);

    showMessage("Ready: press A / B / C");
}

void loop()
{
    M5.update();

    if (M5.BtnA.wasPressed()) Serial.println("A was Pressed");
    if (M5.BtnB.wasPressed()) Serial.println("B was Pressed");
    if (M5.BtnC.wasPressed()) Serial.println("C was Pressed");

    delay(100);
}

Once the sketch has been flashed, button state logs can be viewed via the Serial Monitor.

API

The button section of PaperColor uses the Button_Class from the M5Unified library. For additional button-related APIs, refer to the documentation below:

On This Page