pdf-icon

Arduino入門

2. デバイス&サンプル

6. アプリケーション

Fire Wakeup スリープとウェイクアップ

Fire のスリープ・ウェイクアップに関連する API とサンプルプログラムです。

サンプルプログラム

コンパイル要件

  • M5Stack ボードマネージャーバージョン >= 3.2.2
  • ボードオプション = M5Fire
  • M5Unified ライブラリバージョン >= 0.2.8
  • M5GFX ライブラリバージョン >= 0.2.11
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 28 29 30 31 32 33
#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;
  }
}

このプログラムは、0 から始まり 1 ずつ増加するカウンターを表示します。カウンターが 20 の倍数に達するたびに、デバイスは 5 秒間のライトスリープに入り、その後ウェイクアップしてプログラムを続行します。プログラムをタイマー付きスリープまたはディープスリープ(コメントアウトされている 2 行)に変更すると、ウェイクアップ後にプログラム全体が最初から再開されます。

API

Fire のスリープ・ウェイクアップ機能は、M5Unified ライブラリの Power_Class を使用しています。さらに関連する API については、以下のドキュメントを参照してください:

On This Page