English
English
简体中文
日本語

Arduino Quick Start

2. Devices & Examples

5. Extensions

6. Applications

StickS3 Speaker

StickS3 speaker related APIs and example program.

Example

Compilation Requirements

  • M5Stack Board Manager version >= 3.2.5
  • Development board option = M5StickS3
  • M5Unified library version >= 0.2.12
  • M5GFX library version >= 0.2.18
cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#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);
    M5.Speaker.begin();
    delay(1000);  // Allow the audio hardware to stabilize.
}

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

After power-on, the device will emit two sounds at different frequencies every second.

Audio startup
Allow about 1 second after enabling the StickS3 audio hardware with M5.Speaker.begin() before starting playback to avoid losing the beginning of the audio. When the speaker is initialized by M5.begin(), also allow this time before the first playback.

API

The speaker part of StickS3 uses the Speaker_Class from the M5Unified library. For more related APIs, you can refer to the following documentation:

Page Tools
PDF
On This Page