English
English
简体中文
日本語

Arduino Quick Start

2. Devices & Examples

5. Extensions

6. Applications

PaperMono Wakeup from Sleep

APIs and example programs for PaperMono sleep and wakeup.

Example Programs

Build Requirements

  • M5Stack Board Manager version >= 3.3.9
  • Board option = M5PaperMono
  • M5Unified library version >= 0.2.20
  • M5GFX library version >= 0.2.27
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
#include <M5Unified.h>

void setup()
{
    auto cfg = M5.config();
    cfg.clear_display = false;
    M5.begin(cfg);
    M5.Display.setEpdMode(epd_mode_t::epd_text);
    M5.Display.setTextDatum(middle_center);
    M5.Display.setTextColor(TFT_BLACK);
    M5.Display.setFont(&fonts::FreeSansBold18pt7b);
    M5.Display.clear(TFT_WHITE);
    M5.Display.drawString("PaperMono Wakeup Test", M5.Display.width() / 2, 120);

    M5.Display.setFont(&fonts::FreeSansBold12pt7b);
    M5.Display.drawString("BtnA: Light Sleep 5s", M5.Display.width() / 2, 260);
    M5.Display.drawString("BtnB: Depp Sleep 5s", M5.Display.width() / 2, 320);
    M5.Display.drawString("Press BtnA or BtnB", M5.Display.width() / 2, 400);
}

void loop()
{
    M5.update();

    if (M5.BtnA.wasPressed()) {
        M5.Display.clear(TFT_WHITE);
        M5.Display.setTextDatum(middle_center);
        M5.Display.setTextColor(TFT_BLACK);
        M5.Display.setFont(&fonts::FreeSansBold18pt7b);
        M5.Display.drawString("BtnA: Light Sleep", M5.Display.width() / 2, 180);
        M5.Display.setFont(&fonts::FreeSansBold12pt7b);
        M5.Display.drawString("Sleeping for 5 seconds", M5.Display.width() / 2, 280);
        delay(200);
        M5.Power.lightSleep(5000000, true);

        M5.Display.clear(TFT_WHITE);
        M5.Display.setTextDatum(middle_center);
        M5.Display.setTextColor(TFT_BLACK);
        M5.Display.setFont(&fonts::FreeSansBold18pt7b);
        M5.Display.drawString("BtnA: Wakeup complete", M5.Display.width() / 2, 180);
        M5.Display.setFont(&fonts::FreeSansBold12pt7b);
        M5.Display.drawString("BtnB: Deep Sleep 5s", M5.Display.width() / 2, 320);
    }

    if (M5.BtnB.wasPressed()) {
        M5.Display.clear(TFT_WHITE);
        M5.Display.setTextDatum(middle_center);
        M5.Display.setTextColor(TFT_BLACK);
        M5.Display.setFont(&fonts::FreeSansBold18pt7b);
        M5.Display.drawString("BtnB: Deep Sleep", M5.Display.width() / 2, 180);
        M5.Display.setFont(&fonts::FreeSansBold12pt7b);
        M5.Display.drawString("Wake up after 5 seconds", M5.Display.width() / 2, 280);
        delay(200);
        M5.Power.deepSleep(5000000, true);
    }

    delay(20);
} 

After the program starts, the screen shows two sleep operations. Pressing button A enters light sleep for 5 seconds; after wakeup, execution continues from the line following lightSleep() and indicates that wakeup is complete. Pressing button B enters deep sleep for 5 seconds; after the timed wakeup, the ESP32-S3 resets and starts again from setup().

API

The PaperMono sleep and wakeup features use Power_Class from the M5Unified library. For more information, refer to the following documentation:

Page Tools
PDF
On This Page