Background:
I have a project that immediately starts logging data to an sd card when the device is powered on.
The problem:
It must calculate a new filename for every logging session. The code I use to do this works on other arduino devices, but not on the Teensy 3
The code:
I have a project that immediately starts logging data to an sd card when the device is powered on.
The problem:
It must calculate a new filename for every logging session. The code I use to do this works on other arduino devices, but not on the Teensy 3
The code:
Code:
void getUnusedFilename()
{
int x = 0;
int y = 0;
int z = 0;
//Find the last file on the sd card
while( SD.exists(myFilename) )
{
for (word i = 0; i < 1000; i++)
{ // create new filename w/ 3 digits 000-999
x = i/100;
myFilename[4] = x + '0'; // calculates hundreds position
y = (i-(x*100))/10;
myFilename[5] = y + '0'; // calculates tens position
z = i - (x*100) - (y*10);
myFilename[6] = z + '0'; // subtracts hundreds & tens for single digit
if (! SD.exists(myFilename)) { // only open a new file if it doesn't exist
Serial.print("Next file: ");
Serial.println(myFilename);
break; // leave the loop after finding new filename
}
}
}
Serial.println(myFilename);
}
Last edited: