I have modified the basic trigger sketch so it plays one of 5 randomly selected files when a motion sensor is tripped. Now I would like to have 20 or 30 sound files on the micro sd card to select from. The five files on the card that work now start with numbers 1 through 5. I think I have identified the section of the code I need to change but it looks like it’s doing some kind of subtraction from a character to assign the index number. I am stuck on how to change this to accomodate 20 or 30 files.
The variable definitions are:
char filename[5][13]; I know I would need to change this to however many files I have, eg. [20][13]
int x, index;
SdFile file;
byte result;
char tempfilename[13];
This is the section of code I think I need to change, but all my attempts to change it have not worked. Any help would be appreciated. Thanks.
sd.chdir(“/”,true);
while (file.openNext(sd.vwd(),O_READ))
{
// get filename
file.getFilename(tempfilename);
index = tempfilename[0] - ‘1’;
// Copy the data to our filename array.
strcpy(filename[index],tempfilename);
file.close();
}