Download Wave Shield
Transcript
4. It prints out the name of the file in 8.3 format.
5. If it is a subdirectory, it makes a new object and opens up the subdirectory. Then it
plays all of the wave files in that new directory.
6. If it isn't a subdirectory, it will try to play the file by opening it as a Wave object. That
requires looking through the file and trying to find a Wave header, etc. If it doesn't
succeed it will print out that it's not valid and skip to the next file.
7. If the wave file is valid, it will finally start the file by calling play() on the Wave object.
8. While the wave sound file is playing, it prints out a dot every 100 ms or so.
9. It continues to step 1 until there are no more files to be read.
/*
* play recursively - possible stack overflow if subdirectories too nested
*/
void play(FatReader &dir)
{
FatReader file;
while (dir.readDir(dirBuf) > 0) { // Read every file in the directory one at a time
// skip . and .. directories
if (dirBuf.name[0] == '.')
continue;
Serial.println();
// clear out a new line
for (uint8_t i = 0; i < dirLevel; i++)
Serial.print(' ');
// this is for prettyprinting, put spaces in front
if (!file.open(vol, dirBuf)) {
// open the file in the directory
Serial.println("file.open failed"); // something went wrong :(
while(1);
// halt
}
if (file.isDir()) {
// check if we opened a new directory
putstring("Subdir: ");
printEntryName(dirBuf);
dirLevel += 2;
// add more spaces
// play files in subdirectory
play(file);
// recursive!
dirLevel -= 2;
}
else {
// Aha! we found a file that isnt a directory
putstring("Playing "); printEntryName(dirBuf);
// print it out
if (!wave.create(file)) {
// Figure out, is it a WAV proper?
putstring(" Not a valid WAV"); // ok skip it
} else {
Serial.println();
// Hooray it IS a WAV proper!
© Adafruit Industries https://learn.adafruit.com/adafruit-wave-shield-audio-shield-for-arduino
Page 69 of 90