I have a sketch that monitors and logs multiple sensors. It all works good if it logs everything to one log file. What I want to do is log each sensor to it's own log file. I have a function that assembles the sensor values and a time stamp, then writes it to the SD card. I get a compile error when I try to use a variable in the SD.open statement. Not sure what I'm missing, or what other method I should use.
Here is the error I get:
Time_and_Sensor_Log.ino: In function 'void logit(long int, String, int, String)':
Time_and_Sensor_Log:105: error: no matching function for call to 'SDClass::open(String&, int)'
C:\Program Files (x86)\Arduino\libraries\SD\src/SD.h:73: note: candidates are: File SDClass::open(const char*, uint8_t)
Here are two samples of the code for the Open and Write portions of the function.
/* Sample one that works */
Serial.println("Opening a log file"); // Print msg. to know I got here.
File Datafile = SD.open("Sensor4.txt", FILE_WRITE);
Datafile.println(dataString); // Write assembled data information
Datafile.close();
Serial.println(dataString); // Print it for diag.
/* Sample two causes error*/
String fileName = "Sensor4.txt";
Serial.println("Opening a log file"); // Print msg. to know I got here.
File Datafile = SD.open(fileName, FILE_WRITE);
Datafile.println(dataString); // Write assembled data information
Datafile.close();
Serial.println(dataString); // Print it for diag.