Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @file player-sd-audiokit.ino
- * @brief see https://github.com/pschatzmann/arduino-audio-tools/blob/main/examples/examples-audiokit/player-sd-audiokit/README.md
- * Make sure that the pins are set to off, on, on, off, off
- * @author Phil Schatzmann
- * @copyright GPLv3
- */
- #include "AudioTools.h"
- #include "AudioLibs/AudioKit.h"
- #include "AudioLibs/AudioSourceSD.h" // or AudioSourceIdxSD.h
- #include "AudioCodecs/CodecWAV.h"
- const char *startFilePath="/";
- const char* ext="wav";
- AudioSourceSD source(startFilePath, ext, PIN_AUDIO_KIT_SD_CARD_CS);
- AudioKitStream kit;
- WAVDecoder decoder; // or change to MP3DecoderMAD
- AudioPlayer player(source, kit, decoder);
- void next(bool, int, void*) {
- player.next();
- }
- void previous(bool, int, void*) {
- player.previous();
- }
- void startStop(bool, int, void*) {
- player.setActive(!player.isActive());
- }
- void setup() {
- Serial.begin(115200);
- AudioLogger::instance().begin(Serial, AudioLogger::Warning);
- // setup output
- auto cfg = kit.defaultConfig(RXTX_MODE);
- // sd_active is setting up SPI with the right SD pins by calling
- // SPI.begin(PIN_AUDIO_KIT_SD_CARD_CLK, PIN_AUDIO_KIT_SD_CARD_MISO, PIN_AUDIO_KIT_SD_CARD_MOSI, PIN_AUDIO_KIT_SD_CARD_CS);
- cfg.sd_active = true;
- //cfg.bits_per_sample = 8;
- kit.begin(cfg);
- kit.setVolume(0.9);
- // setup additional buttons
- kit.addAction(PIN_KEY1, startStop);
- kit.addAction(PIN_KEY4, next);
- kit.addAction(PIN_KEY3, previous);
- // setup player
- player.setVolume(0.9);
- player.begin();
- // select file with setPath() or setIndex()
- //player.setPath("/ZZ Top/Unknown Album/Lowrider.mp3");
- //player.setIndex(1); // 2nd file
- }
- void loop() {
- player.copy();
- kit.processActions();
- }
Advertisement
Add Comment
Please, Sign In to add comment