Hi!
I try to write a code for reading song names (.wav) from sd card (from root directory) and stored this songs in an array,but I don't know how !
This is what I wrote
#include <SPI.h>
#include <SD.h>
#include <TMRpcm.h>
#include <IRremote.h>
#define array_size 33
#define RECV_PIN 8
TMRpcm sound;
IRrecv irrecv(RECV_PIN);
decode_results results;
File root;
int music_index = 0;
char *resultsArray[array_size];
//char wavb[array_size];
void setup() {
Serial.begin(9600);
sound.speakerPin = 9;
irrecv.enableIRIn();
if (!SD.begin()) {
Serial.println("initialization failed!");
while (1);
}
root = SD.open("/");
while (true) {
File entry = root.openNextFile();
if (!entry) {
break;
}
if (strstr(entry.name(), ".WAV"))
{
resultsArray[music_index] = (char *)malloc (strlen(entry.name()));
strncpy (resultsArray[music_index], entry.name(), strlen(entry.name()));
music_index++;
Serial.print(music_index, DEC);
Serial.print("- ");
Serial.println(entry.name());
}
}
}
void loop() {
sound.play(resultsArray[0]);
}
Can you help me , please?!
Thank you.