Hello,
I am writing data to series of files in SD card, using the following (part of) code:
String filename =String("LOG-")+String(s)+String(".txt"); //s will be an integer, e.g. 1, 2, 3....
File logFile = SD.open(filename,FILE_WRITE);
However, it keeps giving error "no matching function for call to 'SDClass::open(StringSumHelper&, int)'". I am guessing I cannot use filename in the secend code row? (because when I put "filename" it is working)...
What I want is to make the filename more flexible so I can log the data on different files..Any idea?
Thanks!
p.s. I also tried to include "/"" at the begining and end for filename, still didn't work
char filename[32]; // make it however long you want
int seq = 7; // arbitrary integer value
snprintf(filename, sizeof(filename), "Log-%03d.txt", seq);
// filename now contains "Log-007.txt"
File logFile = SD.open(filename, FILE_WRITE);
When you run this code, the "%03d" in the format string is replaced by a decimal representation of your number, padded with leading zeros as necessary to give three digits. If you don't want that padding you can just leave the 03 out. Google printf for details of the formatting capabilities supported by this function.
char filename[32]; // make it however long you want
int seq = 7; // arbitrary integer value
snprintf(filename, sizeof(filename), "Log-%03d.txt", seq);
// filename now contains "Log-007.txt"
File logFile = SD.open(filename, FILE_WRITE);
When you run this code, the "%03d" in the format string is replaced by a decimal representation of your number, padded with leading zeros as necessary to give three digits. If you don't want that padding you can just leave the 03 out. Google printf for details of the formatting capabilities supported by this function.