English
English
简体中文
日本語
pdf-icon

Arduino Quick Start

2. Devices & Examples

5. Extensions

6. Applications

Atom VoiceS3R Speaker

APIs and example programs related to the speaker on Atom VoiceS3R.

Example Program

Compilation Requirements

  • M5Stack board manager version >= 3.2.2
  • Board option = M5AtomS3R
  • M5Unified library version >= 0.2.8
cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#include "M5Unified.h"
#include "test_audio.h"

// 8bit unsigned 44.1kHz mono (exclude wav header)
extern const uint8_t test_audio[46000];

void setup() {
  M5.begin();
  M5.Speaker.setVolume(64);

  M5.Speaker.tone(7000, 500);  // frequency, duration
  delay(500);
  M5.Speaker.tone(4000, 100);
  delay(500);
}

void loop() {
  M5.Speaker.playRaw(test_audio, sizeof(test_audio) / sizeof(test_audio[0]));
  while (M5.Speaker.isPlaying()) {
    delay(1);
  }
  delay(100);
}

Click to download test_audio.zip, and extract it to obtain the test_audio.h file. Copy the above code into Arduino IDE and save it, then place the test_audio.h file in the same directory alongside the .ino file. Click the upload button, and the program will be compiled and uploaded to the Atom VoiceS3R.

After the upload is complete, the program will start running, first playing beep sounds through the speaker, then playing the wav audio array from the test_audio.h file.

API

The speaker part of Atom VoiceS3R uses the Speaker_Class from the M5Unified library. For more related APIs, please refer to the following documentation:

On This Page