Hello folks, I'm kinda new to arduino and couldn't get to understand this sketch, how could I set it to play a random mp3 file when reset is pressed?
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>
// define the pins used
#define CLK 13 // SPI Clock, shared with SD card
#define MISO 12 // Input data, from VS1053/SD card
#define MOSI 11 // Output data, to VS1053/SD card
// Connect CLK, MISO and MOSI to hardware SPI pins.
// See SPI - Arduino Reference "Connections"
// These can be any pins:
#define RESET 8 // VS1053 reset pin (output)
#define CS 9 // VS1053 chip select pin (output)
#define DCS 6 // VS1053 Data/command select pin (output)
#define CARDCS 10 // Card chip select pin arduino
#define DREQ 7 // VS1053 Data request, ideally an Interrupt pin
Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(RESET, CS, DCS, DREQ, CARDCS);
void setup() {
Serial.begin(9600);
Serial.println("Adafruit VS1053 Simple Test");
musicPlayer.begin(); // initialise the music player
SD.begin(CARDCS); // initialise the SD card
musicPlayer.dumpRegs();
// Set volume for left, right channels. lower numbers == louder volume!
musicPlayer.setVolume(00,00);
// musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_ INT); // timer int
musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT ); // DREQ int
Serial.println("Calling playFullFile");
// Play one file, don't return until complete
musicPlayer.playFullFile("s1.mp3");
//musicPlayer.playFullFile("s2.mp3");
Serial.println("setup done");
// Play another file in the background, REQUIRES interrupts!
// musicPlayer.startPlayingFile("s1.mp3");
}
void loop() {
// File is playing in the background
if (! musicPlayer.playingMusic)
Serial.println("Done playing music");
delay(1000);
}
Thank you all!