Coming from C#, pointers are somewhat foreign although I am grasping the concept. Is it proper to construct methods in the following manner and passing the object (as a parameter) constructed by reference? If not, then please answer how to do this properly.
Initialize the object
Adafruit_VS1053_FilePlayer musicPlayer =
Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);
Method: (use the * for pointer?)
boolean initializeMusicPlayer(Adafruit_VS1053_FilePlayer *mp, uint16_t baudRate) {
musicPlayerSerialPort.begin(baudRate);
// initialise the music player
if (!mp->begin()) { // initialise the music player
Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
return false;
//while (1);
}
Serial.println(F("VS1053 found"));
mp->sineTest(0x44, 500); // Make a tone to indicate VS1053 is working
if (!SD.begin(CARDCS)) {
Serial.println(F("SD failed, or not present"));
return false;
//while (1); // don't do anything more
}
Serial.println("SD OK!");
// Set volume for left, right channels. lower numbers == louder volume!
mp->setVolume(20, 20);
if (!mp->useInterrupt(VS1053_FILEPLAYER_PIN_INT)) {
Serial.println(F("DREQ pin is not an interrupt pin"));
return false;
}
return true;
}
Call the method (Use the ampersand to pass the currently created one by reference?)
if(initializeMusicPlayer(&musicPlayer, 9600) == true) {
tempString = tempString + "MusicPlayer initialized!";
Serial.println(tempString);
//when adding lcd, print the above to lcd and remove the serial print
}