#include #include #include int yellowLED = 21; int pb = 14; int pbval; int pb2 = 13; int pbval2; int pb3 = 12; int pbval3; Sd2Card card; SdVolume volume; SdFile root; const int chipSelect = 10; File myFile; void setup() { /////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////DECLARATIONS///////////////////////////////////// pinMode(yellowLED, OUTPUT); pinMode(pb, INPUT_PULLUP); pinMode(pb2, INPUT_PULLUP); pinMode(pb3, INPUT_PULLUP); /////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////SD INITIALIZATION/////////////////////////////////// Serial.begin(9600); Serial.print("\nInitializing SD card..."); pinMode(10, OUTPUT); if (!card.init(SPI_HALF_SPEED, chipSelect)) { Serial.println("Initialization failed."); return; } else { Serial.println("Initialization successful."); } /////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////SD INFO/////////////////////////////////////////// if (!volume.init(card)) { } uint32_t volumesize; volumesize = volume.blocksPerCluster(); // clusters are collections of blocks volumesize *= volume.clusterCount(); // we'll have a lot of clusters volumesize *= 512; // SD card blocks are always 512 bytes Serial.print("Volume size (Mbytes): "); volumesize /= 1048576; Serial.println(volumesize); Serial.println("\nFiles found on the card: "); root.openRoot(volume); root.ls(); /////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////AUDIO SETUP//////////////////////////////////////// SPI.setClockDivider(2); Audio.begin(88200, 100); /////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////MAIN SETUP///////////////////////////////////////// if (!SD.begin(10)) { } } //////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////MAIN LOOP/////////////////////////////////////////// void loop() { pbval = digitalRead(pb); pbval2 = digitalRead(pb2); pbval3 = digitalRead(pb3); /////// test /////// if (pbval == 0) // 0 = press { int count=0; File myFile = SD.open("test.wav"); if (!myFile) // error msg if myFile variable doesn't get set { Serial.println("error opening test.wav"); } const int S=1024; // Number of samples to read in block short buffer[S]; Serial.print("Playing"); // Plays until file finished while (myFile.available()) { myFile.read(buffer, sizeof(buffer)); // read from file into buffer int volume = 1024; Audio.prepare(buffer, S, volume); // prepare samples from file to audio buffer, set volume Audio.write(buffer, S); // write audio out DAC0 count++; if (count == 100) { Serial.print("."); count = 0; } } myFile.close(); Serial.println("End of file. Thank you for listening!"); } ////// flam1 ////// if (pbval2 == 0) // 0 = press { int count=0; File myFile = SD.open("flam1.wav"); if (!myFile) // error msg if myFile variable doesn't get set { Serial.println("error opening bass.wav"); } const int S=1024; // Number of samples to read in block short buffer[S]; Serial.print("Playing"); // Plays until file finished while (myFile.available()) { myFile.read(buffer, sizeof(buffer)); // read from file into buffer int volume = 1024; Audio.prepare(buffer, S, volume); // prepare samples Audio.write(buffer, S); // write audio out DAC count++; if (count == 100) { Serial.print("."); count = 0; } } myFile.close(); Serial.println("End of file. Thank you for listening!"); } } ////////////////////////////////////////////////////////////////////////////////////////////