Arduino 上手教程
Tough 休眠唤醒相关API与案例程序。
#include <M5Unified.h>#include <M5GFX.h> int myIndex = 0; void setup() { M5.begin(); M5.Display.setRotation(1); M5.Display.setFont(&fonts::FreeMonoBold12pt7b); M5.Display.clear(); M5.Display.print("Sleep & Wakeup Test\n");} void loop() { myIndex++; M5.Display.setCursor(0, 50); M5.Display.printf(" %4d", myIndex); delay(50); if (myIndex % 20 == 0) { // M5.Power.timerSleep(5); // in seconds // M5.Power.deepSleep(5000000, false); // in microseconds M5.Power.lightSleep(5000000, false); // in microseconds M5.Display.setCursor(0, 0); M5.Display.print("Sleep & Wakeup Test\n"); } if (myIndex >= 1000) { myIndex = 0; }}
该程序将会显示一个从 0 开始自增 1 的计数器,每次增长到 20 的倍数时让设备进入浅度休眠 5 秒然后唤醒,程序继续。如果将程序改为计时休眠或者深度休眠(注释掉的两行),则唤醒后整个程序会从头开始。
Tough 休眠唤醒部分使用了 M5Unified
库中的 Power_Class
,更多相关的API可以参考下方文档: