
Arduino 上手教程
PowerHub Wakeup 休眠唤醒相关 API 与案例程序。
#include <M5Unified.h>
int myIndex = 0;
void setup() {
M5.begin();
M5.Led.setBrightness(255);
Serial.begin(115200);
Serial.println("\n\nPowerHub Sleep & Wakeup Test");
delay(1000);
}
void loop() {
myIndex++;
Serial.printf("%d ", myIndex);
M5.Led.setAllColor(TFT_WHITE);
M5.Led.display();
delay(200);
if (myIndex % 20 == 0) {
M5.Led.setAllColor(TFT_BLACK);
M5.Led.display();
M5.Power.timerSleep(5); // in seconds
// M5.Power.deepSleep(5000000, false); // in microseconds
// M5.Power.lightSleep(5000000, false); // in microseconds
}
if (myIndex >= 1000) {
myIndex = 0;
}
}该程序将会点亮 LED 灯并在串口打印一个从 0 开始自增 1 的计数器,每次增长到 20 的倍数时让设备进入计时休眠 5 秒(LED 灯熄灭)然后唤醒,程序重新开始(LED 灯点亮)。
PowerHub Wakeup 休眠唤醒部分驱动使用了M5Unified库中的Power_Class,更多相关的 API 可以参考下方文档: