pdf-icon

Arduino 上手教程

2. 设备开发 & 案例程序

5. 拓展模块

6. 应用案例

CoreS3 Speaker 扬声器

CoreS3 Speaker 扬声器相关 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

CoreS3 Speaker部分驱动使用了 M5Unified 库中的 Speaker_Class, 更多相关的API可以参考下方文档:

On This Page