In the example below, I have two functions that write numbers to two different files on an SD card. I'm using the SdFat library.
Is there any way I can combine the two functions into one, so that I can call (for example): writeToFile(int t, FileName "filename1.txt");
?
In the example below, to write a value to the "temperature.txt" file, I would like to be able to call: writeToFile(7, "temperature.txt");
In my sketch I have about a dozen functions that are writing to a dozen different files, so it would be very handy to be able to combine them into one function.
I think the main part I'm stuck on is I have no idea what the filename variable would be, or how to pass the filename to the function.
#include <SdFat.h>
SdFat sd;
void setup() {
if (!sd.begin(chipSelect, SPI_HALF_SPEED)) {
sd.initErrorHalt();
}
setTemperature(7);
setFanSpeed(4);
}
void setTemperature(int t) {
SdFile rdfile("temperature.txt", O_WRITE);
rdfile.rewind();
rdfile.println(t);
rdfile.close();
}
void setFanSpeed(int t) {
SdFile rdfile("fanspeed.txt", O_WRITE);
rdfile.rewind();
rdfile.println(t);
rdfile.close();
}