I'm attempting to create a .wav file player that will display the names of the .wav files stored on the SD card module on an LCD display. Using buttons, it should be able to scroll through the list of files. Upon finding the file the user wants to play, clicking another button will play the file on a speaker or headphones or whatever. The LCD and SD card module are working fine, i tested them earlier. The real problem is compiling the code. I'm attempting to store every filename in an array of strings. However, apparently the developer of the TMRpcm library, which is what im using to play the files, made his play() function to take char* data types as the argument. Why is it this and not a string? I have tried casting my strings to char* by using (char*), it didn't work. I recognize that the asterisk indicates it has something to do with pointers and references, i'm just unaware of why this is. Could I edit the library to make the function take strings instead, and if so, how would I do so? Ive already tried editing the .h and .cpp files, and it resulted in more errors. Any recommendations on how to get around this issue? I'd also like to know why printing file.name() in the serial monitor results in only 5 letters of the filename being displayed. I'm using an atmega328 on a breadboard and my wiring is fine. I'm running arduino 1.8.10 on Linux Mint. The lines indicated with comments saying error in all caps indicate where the errors are being thrown. I'm also completely new to this forum and has posted this on project guidance earlier, but now I realize its more appropriate in this section, but im unsure of how to delete the post in the other section.
#include <TMRpcm.h>
#include <pcmConfig.h>
#include <pcmRF.h>
#include <LiquidCrystal.h>
#include <SPI.h>
#include <SD.h>
LiquidCrystal lcd(9, 4, 5, 6, 7, 8);
File root;
File counterEntry;
byte volumeLevel = 5;
byte counter = 1;
TMRpcm music;
boolean marker = false;
long positionNumber = 0;
boolean ScrollUpButton = 0;
boolean ScrollDownButton = 0;
boolean playButton = 0;
boolean volumeUpButton = 0;
boolean volumeDownButton = 0;
boolean flowStateButton = 0;
byte repeat = 1;
byte continuous = 2;
byte shuffle = 3;
byte flowState = 1;
String Songs[450] = {};
void setup() {
lcd.begin(16, 2);
SD.begin(10);
music.speakerPin = 3;
pinMode(A0, INPUT); //volume up button
pinMode(A1, INPUT); //volume down button
pinMode(A2, INPUT); //play/pause button
pinMode(A3, INPUT); //scroll up button
pinMode(A4, INPUT); //scroll down button
pinMode(A5, INPUT); //flowstate button
root = SD.open("/");
root.rewindDirectory();
music.setVolume(volumeLevel);
randomSeed(analogRead(2));
counterEntry = root.openNextFile();
while(counterEntry != 0)
{
counterEntry = root.openNextFile();
counter++;
}
root.rewindDirectory();
counterEntry = root.openNextFile();
for(int x = 0; x <= counter; x++)
{
Songs[x] = counterEntry.name();
counterEntry = root.openNextFile();
}
lcd.print(Songs[0]);
}
void loop() {
if(marker == true)
{
music.play(Songs[positionNumber]); //ERROR
}
ScrollDownButton = digitalRead(A3);
if(ScrollDownButton == HIGH && positionNumber < counter)
{
positionNumber++;
lcd.print(Songs[positionNumber]);
}
ScrollUpButton = digitalRead(A4);
if(ScrollUpButton == HIGH && positionNumber > 0)
{
positionNumber--;
lcd.print(Songs[positionNumber]);
}
playButton = digitalRead(A2);
if(playButton == HIGH)
{
if(music.isPlaying() == 0)
{
music.play(Songs[positionNumber]); //ERROR
marker = true;
}
else if(music.isPlaying() == 1)
{
music.pause();
}
}
volumeUpButton = digitalRead(A0);
if(volumeUpButton == HIGH && volumeLevel <= 7)
{
volumeLevel++;
music.setVolume(volumeLevel);
}
volumeDownButton = digitalRead(A1);
if(volumeDownButton == HIGH && volumeLevel >= 0)
{
volumeLevel--;
music.setVolume(volumeLevel);
}
flowStateButton = digitalRead(A5);
if(flowStateButton == HIGH)
{
if(flowState == repeat)
{
flowState = continuous;
}
else if(flowState == continuous)
{
flowState = shuffle;
}
else if(flowState == shuffle)
{
flowState = repeat;
}
}
if(flowState == repeat)
{
}
else if(flowState == continuous)
{
if(positionNumber == counter)
{
positionNumber = 0;
}
else
{
positionNumber++;
}
}
else if(flowState == shuffle)
{
positionNumber = random(counter+1);
}
}
error message: Output Error Message: /home/santiago/Documents/Engineering Projects/_wav_File_Player_code/_wav_File_Player_code.ino: In function 'void loop()':
_wav_File_Player_code:69:37: error: no matching function for call to 'TMRpcm::play(String&)'
music.play(Songs[positionNumber]);
^
In file included from /home/santiago/Documents/Engineering Projects/_wav_File_Player_code/_wav_File_Player_code.ino:1:0:
/home/santiago/Arduino/libraries/TMRpcm-master/TMRpcm.h:31:7: note: candidate: void TMRpcm::play(char*)
void play(char* filename);
^~~~
/home/santiago/Arduino/libraries/TMRpcm-master/TMRpcm.h:31:7: note: no known conversion for argument 1 from 'String' to 'char*'
/home/santiago/Arduino/libraries/TMRpcm-master/TMRpcm.h:55:8: note: candidate: void TMRpcm::play(char*, long unsigned int)
void play(char* filename, unsigned long seekPoint);
^~~~
/home/santiago/Arduino/libraries/TMRpcm-master/TMRpcm.h:55:8: note: candidate expects 2 arguments, 1 provided
_wav_File_Player_code:94:39: error: no matching function for call to 'TMRpcm::play(String&)'
music.play(Songs[positionNumber]);
^
In file included from /home/santiago/Documents/Engineering Projects/_wav_File_Player_code/_wav_File_Player_code.ino:1:0:
/home/santiago/Arduino/libraries/TMRpcm-master/TMRpcm.h:31:7: note: candidate: void TMRpcm::play(char*)
void play(char* filename);
^~~~
/home/santiago/Arduino/libraries/TMRpcm-master/TMRpcm.h:31:7: note: no known conversion for argument 1 from 'String' to 'char*'
/home/santiago/Arduino/libraries/TMRpcm-master/TMRpcm.h:55:8: note: candidate: void TMRpcm::play(char*, long unsigned int)
void play(char* filename, unsigned long seekPoint);