Arduino Quick Start
APIs and example programs related to Fire sleep and wake functions.
#include <M5Unified.h>
int myIndex = 0;
void setup() {
M5.begin();
M5.Display.setRotation(1);
M5.Display.setFont(&fonts::FreeMonoBold12pt7b);
M5.Display.clear();
M5.Display.println("Sleep & Wakeup Test");
}
void loop() {
myIndex++;
M5.Display.setCursor(0, 50);
M5.Display.printf(" %4d", myIndex);
delay(50);
if (myIndex % 20 == 0) {
M5.Power.lightSleep(5000000, false); // in microseconds
// M5.Power.deepSleep(5000000, false); // in microseconds
// M5.Power.timerSleep(5); // in seconds
M5.Display.setCursor(0, 0);
M5.Display.println("Sleep & Wakeup Test");
}
if (myIndex >= 1000) {
myIndex = 0;
}
}
This program will display a counter starting from 0 and incrementing by 1. Each time it reaches a multiple of 20, the device will enter light sleep for 5 seconds and then wake up, continuing the program. If the program is modified to use timed sleep or deep sleep (like the two commented lines), the entire program will restart from the beginning after waking up.
The Fire sleep and wake functionality uses the Power_Class
from the M5Unified
library. For more related APIs, please refer to the following documentation: