pdf-icon

Arduino Quick Start

2. Devices & Examples

Paper Button Rotary Button

API references and example programs related to the Paper rotary encoder button.

Example Program

Compilation Requirements

  • M5Stack Board Manager version >= 2.1.4
  • Board selection = M5Paper
  • M5Unified library version >= 0.2.5
  • M5GFX library version >= 0.2.7
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 34 35 36 37 38
#include <M5Unified.h>
#include <M5GFX.h>

void setup() {
  M5.begin();
  M5.Display.setRotation(0);
  M5.Display.setFont(&fonts::FreeMonoBold24pt7b);
  M5.Display.setEpdMode(epd_fast);  // epd_quality, epd_text, epd_fast, epd_fastest
  Serial.begin(115200);

  M5.Display.clear();
  M5.Display.setCursor(20, 100);
  M5.Display.print("Rotary Button Test");
  Serial.println("Rotary Button Test");

  M5.Display.setCursor(40, 300);
  M5.Display.print("____ was pressed");
}

void loop() {
  M5.update();

  if (M5.BtnA.wasPressed()) {
    M5.Display.setCursor(40, 300);
    M5.Display.print("BtnA was pressed");
    Serial.println("BtnA was pressed");
  }
  if (M5.BtnB.wasPressed()) {
    M5.Display.setCursor(40, 300);
    M5.Display.print("BtnB was pressed");
    Serial.println("BtnB was pressed");
  }
  if (M5.BtnC.wasPressed()) {
    M5.Display.setCursor(40, 300);
    M5.Display.print("BtnC was pressed");
    Serial.println("BtnC was pressed");
  }
}

This program will display the button states on the screen. BtnA corresponds to rotating the wheel upward (G37), BtnB corresponds to pressing the wheel (G38), and BtnC corresponds to rotating the wheel downward (G39).

API

The Paper button section uses the Button_Class from the M5Unified library. For more related APIs, refer to the documentation below:

On This Page