Hello,
I want to use a subroutine that can read alternate files from the SD card. If I delcare 2 FIles such as File phoneNumFile, and File fileTwo, and have them both open at the same time, I would like to use a function to do the same process alternatly. How do you pass a File type to the subroutine? I have my code following.
char phoneNumbers[100];
char authNumbers[100];
File phoneNumFile;
File authNumFile;
void getPhoneNumbers(phoneNumbers,"phoneNum.txt", phoneNumFile)
void getPhoneNumbers(authNumbers,"authNum.txt", authNumFile)
void getPhoneNumbers(char anyPhoneNumbers[100], char nameFile[12] ="", File = anyFile){
memset (anyPhoneNumbers,'\0',100);
int charPos = 0;
char thisChar;
anyFile = SD.open("nameFile", FILE_READ);
if (! anyFile) {
Serial.println("error opening nameFile.txt");
// Wait forever since we cant read data
while (1) ;
}
if (anyFile) {
while (anyFile.available()) {
thisChar = anyFile.read();
//READ PHONE NUMBERS AS A STRING TO BUFFER TO PARSE LATER
if(charPos < 99) {
anyPhoneNumbers[charPos] = thisChar;
charPos++;
anyPhoneNumbers[charPos] = 0;
}
}
charPos++;
anyPhoneNumbers[charPos] = '\r';
Serial.println(charPos,DEC);
charPos++;
anyPhoneNumbers[charPos] = '\n';
// Serial.write(thisChar);
anyFile.close();
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening nameFile.txt");
}
}
This code does what I want but I am trying to make it into a subroutine. I don't seem to have handle on this. I can just do it in line and it works just fine but it would be nice to be able to call the routine and pass it the buffer name, file name and the File associated with filename. I can't get this code to compile. The subroutine comples but not the calling line, Any suggestions?
Stank