First the code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
int sample1 = 0;//keep track of sample number selected
const char *mySamples[] = {"\"EERIE.WAV\"", "\"LA.WAV\"", "\"RCALOCK3.WAV\"",
"\"TIMESPAN.WAV\"", "\"BEADS.WAV\"", "\"RCA2.WAV\"", "\"RCALOCK2.WAV\"", "\"RCALOOP3.WAV\""};
void setup() {
// put your setup code here, to run once:
Serial.begin(11520);
SPI.setMOSI(7);
SPI.setSCK(14);
if (!(SD.begin(10))) {
while (1) {
Serial.println("Unable to access the SD card");
delay(500);
}
}
}
void loop() {
// put your main code here, to run repeatedly:
playSdWav1.play(mySamples[0]);
delay(10); //to allow parsing of SD
}
I am looking to create a music sampler. One thing I wish to do at some point is have a user push one of 8 buttons, and when that button is pressed it will write a value (0-7 depending on which is pressed) to the variable "sample1=0". I hope to put sample1 inside the function as such:
playSdWav1.play(mySamples[sample1]);
My goal here is to use the value of sample1 as a reference for the a certain filename in the mySamples array. That way if sample1 = 0, the function will read the following:
playSdWav1.play("EERIE.WAV");
And then it will play that sample. The issue is, it is not playing the sample if I do the referencing. I have done some troubleshooting and found several things. One, if I write:
playSdWav1.play("EERIE.WAV");
It will play the sample perfectly. I have tried increasing the delay time to 1000 ms, thinking I'm not giving enough time to do the referencing and still no luck.
Now, if I write the following:
Serial.println(mySamples[sample1]);
The Serial prints: "EERIE.WAV". So I know it might not be an issue with the quotation marks. If I do:
Serial.println(sizeof[mySamples[0]);
The serial returns a value of 4. This is weird, aren't characters 1 or 2 bytes. Is it possibly converting the name "EERIE.WAV" to an int? One more thing I've found. The following was taken from the cpp file for the playSdWav function. It requires a const char *filename:
AudioPlaySdWav::play(const char *filename)
So I am confused at this point why when I called the array mySamples, I'm not able to receive a const char*
Thank you