pdf-icon

Arduino入門

2. デバイス&サンプル

Paper Wakeup(休眠と起床)

Paperの休眠およびウェイクアップに関するAPIとサンプルプログラム。

サンプルプログラム

ビルド要件

  • M5Stack ボードマネージャバージョン >= 2.1.4
  • ボードの選択 = M5Paper
  • M5Unified ライブラリバージョン >= 0.2.5
  • M5GFX ライブラリバージョン >= 0.2.7
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 34 35 36 37 38
#include <M5Unified.h>
#include <M5GFX.h>

int myIndex = 0;

void setup() {
  M5.begin();
  M5.Display.setRotation(0);
  M5.Display.setFont(&fonts::FreeMonoBold24pt7b);
  M5.Display.setEpdMode(epd_fast);  // epd_quality, epd_text, epd_fast, epd_fastest

  M5.Display.clear();
  M5.Display.print("\nSleep & Wakeup Test\n");
}

void loop() {
  myIndex++;

  M5.Display.setCursor(0, 120);
  M5.Display.printf("    %4d", myIndex);
  delay(200);

  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.getPanel()->setSleep(true);
    // delay(5000);  // in milliseconds
    // M5.Display.getPanel()->setSleep(false);

    M5.Display.setCursor(0, 0);
    M5.Display.print("\nSleep & Wakeup Test\n");
  }
  if (myIndex >= 1000) {
    myIndex = 0;
  }
}

このプログラムは、0から始まり1ずつ増加するカウンターを表示します。カウントが20の倍数になるたびに、デバイスは5秒間のライトスリープに入り、その後再び起動して処理を継続します。プログラムを変更してタイマーによるスリープやディープスリープ(コメントアウトされている2行)を使用すると、起床後はプログラム全体が最初から再実行されます。

API

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

On This Page