
Arduino Quick Start
APIs and example programs related to the Cardputer Speaker, applicable to both Cardputer and Cardputer-Adv.
#include "M5Cardputer.h"
void setup() {
auto cfg = M5.config();
M5Cardputer.begin(cfg);
}
void loop() {
M5Cardputer.Speaker.tone(7000, 100); // frequency, duration
delay(1000);
M5Cardputer.Speaker.tone(4000, 20); // frequency, duration
delay(1000);
}Open the example program Advanced -> Speaker_SD_wav_file from the M5Unified driver library. As shown by the arrow in the image below, change the value of SDCARD_CSPIN to GPIO_NUM_12, and update the filename in files[] to the path of the WAV file you want to play (the leading / indicates the root directory of the microSD card). Click the upload button to compile and flash the program to the device. Insert the microSD card into the device (with the card’s contacts facing opposite to the device’s screen). When the device starts, the specified WAV files in the program will be played sequentially.
The M5Cardputer library is built on top of the M5Unified library. The speaker driver uses the Speaker_Class from the M5Unified library. For more detailed APIs, please refer to the following documentation: