pdf-icon

Arduino入門

2. デバイス&サンプル

5. 拡張モジュール&サンプル

アクセサリー

6. アプリケーション

StopWatch Vibration

StopWatch 振動モーター関連APIとサンプルプログラム。

サンプルプログラム

コンパイル要件

  • M5Stack ボードマネージャーバージョン >= 3.3.7
  • ボードオプション = M5StopWatch
  • M5Unified ライブラリバージョン >= 0.2.15
  • M5GFX ライブラリバージョン >= 0.2.21
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
#include <M5Unified.h>

void setup(void) {
  auto cfg = M5.config();
  M5.begin(cfg);

  M5.Display.setTextDatum(middle_center);
  M5.Display.setTextFont(&fonts::FreeMonoBold12pt7b);
  M5.Display.setTextSize(1);
  M5.Display.drawString("Vibration Test", M5.Display.width() / 2, M5.Display.height() / 2);
}

void loop(void) {
  M5.Power.setVibration(10);
  delay(500);
  M5.Power.setVibration(40);
  delay(500);
  M5.Power.setVibration(70);
  delay(500);
  M5.Power.setVibration(100);
  delay(500);
  M5.Power.setVibration(130);
  delay(500);
  M5.Power.setVibration(160);
  delay(500);
  M5.Power.setVibration(190);
  delay(500);
  M5.Power.setVibration(210);
  delay(500);
  M5.Power.setVibration(240);
  delay(500);
}

StopWatch 振動モーターは、振動強度を徐々に高めながらループ動作します。効果は以下の通りです:

API

StopWatch の振動モーター部分では M5Unified ライブラリの Power_Class を使用しています。関連APIの詳細は以下のドキュメントを参照してください:

On This Page