instrumentek
Well-known member
Hi;
I'm wondering if there is a way to call different file names to one file declaration so I can save on repeated coding for different file names. here is an example of my code:
I get the following error code "'myFile' was not declared in this scope". I have tried declaring "File myFile" before the if statements and it complies but fails to load the file
________________________________________________________
- Teensy 3.1
- Arduino 1.63
- Teensy loader 1.25
Thanks for any advice
I'm wondering if there is a way to call different file names to one file declaration so I can save on repeated coding for different file names. here is an example of my code:
Code:
#include <SD.h>
#include <SPI.h>
//________________________________________________
void setup()
{
Serial.begin(9600);
SD.begin();
}
//________________________________________________
void loop()
{
fileDump(1);
fileDump(2);
fileDump(3);
}
//________________________________________________
int fileDump(int fileNumber)
{
if (fileNumber == 1)
File myFile = SD.open("test1.txt");
if (fileNumber == 2)
File myFile = SD.open("test2.txt");
if (fileNumber == 3)
File myFile = SD.open("test3.txt");
//_________________________________do file stuff
while (myFile.available())
{
Serial.write(myFile.read());
}
myFile.close();
}
I get the following error code "'myFile' was not declared in this scope". I have tried declaring "File myFile" before the if statements and it complies but fails to load the file
________________________________________________________
- Teensy 3.1
- Arduino 1.63
- Teensy loader 1.25
Thanks for any advice