Last active
November 2, 2022 13:33
-
-
Save carlynorama/9300525 to your computer and use it in GitHub Desktop.
Creating a lot of files on an SD Card with an Arduino. Code complies. Keeping it as a reminder of how to work with String to char array conversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void generateFiles() { | |
//derived from code found at http://forum.arduino.cc/index.php?topic=57460.0 | |
String fileName = String(); | |
String message = String(); | |
unsigned int filenumber = 1; | |
while(!filenumber==0) { | |
fileName = "file_"; | |
fileName += filenumber; | |
fileName += ".txt"; | |
message = fileName; | |
char charFileName[fileName.length() + 1]; | |
fileName.toCharArray(charFileName, sizeof(charFileName)); | |
if (SD.exists(charFileName)) { | |
message += " exists."; | |
filenumber++; | |
} | |
else { | |
File dataFile = SD.open(charFileName, FILE_WRITE); | |
message += " created."; | |
dataFile.close(); | |
filenumber = 0; | |
} | |
Serial.println(message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment