Arduino入門

2. デバイス&サンプル

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

アクセサリー

6. アプリケーション

StickC-Plus SE スピーカー

StickC-Plus SE のスピーカーに関する API とサンプルプログラムです。

サンプルプログラム

コンパイル要件

  • M5Stack ボードマネージャーバージョン >= 3.3.8
  • ボードオプション = M5StickCPlus
  • M5Unified ライブラリバージョン >= 0.2.18
  • M5GFX ライブラリバージョン >= 0.2.24
cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include "M5Unified.h"

void setup() {
    M5.begin();
    M5.Lcd.setRotation(1);
    M5.Lcd.setTextDatum(middle_center);
    M5.Lcd.setTextFont(&fonts::FreeMonoBold9pt7b);
    M5.Lcd.clear();
    M5.Lcd.drawString("Speaker", M5.Lcd.width() / 2, M5.Lcd.height() / 2);
    delay(100);
}

void loop() {
    M5.Speaker.tone(7000, 100);  // frequency, duration
    delay(1000);
    M5.Speaker.tone(4000, 200);  // frequency, duration
    delay(1000);
}

デバイスの電源を入れると、1 秒間隔で異なる周波数の音を 2 回鳴らします。

API

StickC-Plus SE のスピーカーには、M5Unified ライブラリの Speaker_Class を使用しています。その他の API については、以下のドキュメントを参照してください。

Page Tools
PDF
On This Page