English
English
简体中文
日本語

Arduino Quick Start

2. Devices & Examples

5. Extensions

6. Applications

StickC-Plus Buzzer ブザー

M5StickCPlusのブザーに関する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 19 20 21 22 23 24 25 26 27
#include "M5Unified.h"

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

    // StickC Plus has a built-in buzzer/speaker.
    cfg.internal_spk = true;

    M5.begin(cfg);

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

void loop() {
    M5.Speaker.tone(7000, 100);
    delay(1000);

    M5.Speaker.tone(4000, 200);
    delay(1000);
}
Page Tools
PDF
On This Page