Arduino Quick Start
APIs and example programs related to the speaker on Atom EchoS3R.
#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 EchoS3R.
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.
The speaker part of Atom EchoS3R uses the Speaker_Class
from the M5Unified
library. For more related APIs, please refer to the following documentation: