pdf-icon

Arduino Quick Start

2. Devices & Examples

6. Applications

Dial Wakeup

APIs and example programs related to Dial sleep and wakeup.

Example Program

Build Requirements

  • M5Stack board manager version >= 3.2.2
  • Board option = M5Dial
  • M5Dial library version >= 1.0.3
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
#include <M5Dial.h>

void setup() {
  auto cfg = M5.config();
  M5Dial.begin(cfg, false, false);  // encoder, RFID

  M5Dial.Display.setTextColor(GREEN);
  M5Dial.Display.setTextDatum(middle_center);
  M5Dial.Display.setTextFont(&fonts::FreeSerifItalic18pt7b);
  M5Dial.Display.setTextSize(1);

  M5Dial.Display.drawString("Press Btn", M5Dial.Display.width() / 2, M5Dial.Display.height() / 2 - 60);
  M5Dial.Display.drawString("to sleep",  M5Dial.Display.width() / 2, M5Dial.Display.height() / 2 - 20);
  M5Dial.Display.drawString("After 5s",  M5Dial.Display.width() / 2, M5Dial.Display.height() / 2 + 20);
  M5Dial.Display.drawString("Wakeup",    M5Dial.Display.width() / 2, M5Dial.Display.height() / 2 + 60);
}

void loop() {
  M5Dial.update();

  if (M5Dial.BtnA.wasPressed()) {
    M5Dial.Power.timerSleep(5);
    // M5Dial.Power.timerSleep(const rtc_time_t& time);
    // M5Dial.Power.timerSleep(const rtc_date_t& date, const rtc_time_t& time);
    // M5Dial.Power.powerOff();  // shutdown
  }
}

After compiling and uploading the above program, press the button and the device will enter sleep for 5 seconds, then automatically wake up.

API

The M5Dial library is built on top of the M5Unified library. The power subsystem uses the Power_Class from M5Unified. For more related APIs, please refer to the following document:

On This Page