I am trying to write a program that writes data to a file, including a timestamp (mytime). I am getting the following error when trying to append the timestamp to the file:
"error: converting to 'String' from initializer list would use explicit constructor 'String::String(long int, unsigned char)'
appendFile("DATA.TXT", mytime);"
mytime is defined by the global variable:
"unsigned long mytime=0;"
and the timestamp is updated in a loop by the following instruction:
"mytime=millis();"
unsigned long mytime=0;
loop{
mytime = millis();
appendFile("DATA.TXT", mytime);
}
void appendFile(String fileName, String data){
resetALL(); //Reset the module
set_USB_Mode(0x06); //Set to USB Mode
diskConnectionStatus(); //Check that communication with the USB device is possible
USBdiskMount(); //Prepare the USB for reading/writing - you need to mount the USB disk for proper read/write operations.
setFileName(fileName); //Set File name
fileOpen(); //Open the file
filePointer(false); //filePointer(false) is to set the pointer at the end of the file. filePointer(true) will set the pointer to the beginning.
fileWrite(data); //Write data to the end of the file
fileClose(0x01); //Close the file using 0x01 - which means to update the size of the file on close.
}
*note: I did not write the appendFile function. this had been provided to me for this project
The code is still incomplete, no includes (which libraries?) and no setup and you did not use code tags to format it. The 15% of the code you wrote your self will become a problem, the loop function will be executed very fast over and over, and the code will eventually add contents to the file so quick that it will generate a huge amount of data. "mytime" is a numeric value which starts from zero when the arduino is reset and then it will increment to 2^32 and start over again. If you want to write that number to the file, you will need to convert it to a cstring (do not use the "String" class, it will become a problem for you!).
char buffer[15];
ultoa(mytime, buffer, 10); //Unsigned Long TO Ascii
appendFile("FILE.TXT", buffer);
unfortunately, I am aware of a lot of the poor practice being used in this program. I did not make the decisions, but the program was mostly already written for me, and I'm just trying to reformat the output that it produces.