简体中文
English
简体中文
日本語

Arduino 上手教程

2. 设备开发 & 案例程序

5. 扩展模块

6. 应用案例

StickC-Plus Buzzer 蜂鸣器

M5StickCPlus Buzzer 蜂鸣器相关 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