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秒間のライトスリープに入り、その後復帰してプログラムを継続します。プログラムをタイマー・スリープやディープ・スリープに変更した場合(コメントアウトされている2行)、スリープから復帰後にプログラム全体が最初から再実行されます。
Tough Wakeup 機能には、M5Unified
ライブラリの Power_Class
が使用されています。関連するAPIの詳細は以下のドキュメントを参照してください: