pdf-icon

Arduino入門

2. デバイス&サンプル

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

アクセサリー

6. アプリケーション

StackChan Speaker スピーカー

StackChan スピーカー関連の API とサンプルプログラムです。

サンプルプログラム

コンパイル要件

  • M5Stack ボード管理バージョン >= 3.2.2
  • ボード設定 = M5CoreS3
  • M5Unified ライブラリバージョン >= 0.2.11
cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#include "M5Unified.h"

void setup() {
    auto cfg = M5.config();
    M5.begin(cfg);
    M5.Display.setRotation(1);
    M5.Display.setTextColor(GREEN);
    M5.Display.setTextDatum(middle_center);
    M5.Display.setTextFont(&fonts::Orbitron_Light_24);
    M5.Display.setTextSize(1);
    M5.Display.drawString("Speaker Test", M5.Display.width() / 2,
                                M5.Display.height() / 2);
}

void loop() {
    M5.Speaker.tone(10000, 100);
    delay(1000);
    M5.Speaker.tone(4000, 20);
    delay(1000);
}

書き込みが完了すると、StackChan のスピーカーから異なる周波数の音(10kHz と 4kHz)が順番に鳴り、それぞれ 1 秒間持続します。

API

StackChan スピーカー機能は、M5Unified ライブラリの Speaker_Class を使用しています。関連する API の詳細については、以下のドキュメントをご参照ください:

On This Page