Skip to content

Instantly share code, notes, and snippets.

@tahnok
Last active May 16, 2019 01:39
Show Gist options
  • Save tahnok/229c9c8d763cb08f9bc9ce7fc25948ce to your computer and use it in GitHub Desktop.
Save tahnok/229c9c8d763cb08f9bc9ce7fc25948ce to your computer and use it in GitHub Desktop.
#include <SD.h>
const int sdChipSelect = 10;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
if (!SD.begin(sdChipSelect)) {
while(1) {}
}
char filename[13];
findFilename2(filename);
Serial.print("outside:");
Serial.println(filename);
File newOne = SD.open(filename, FILE_WRITE);
newOne.write("hi");
newOne.close();
Serial.println("done");
}
void loop() {
// put your main code here, to run repeatedly:
}
void findFilename2(char* filename) {
filename = "FLIGHT00.csv";
for (uint8_t i = 0; i < 100; i++) {
if (i < 10) {
itoa(i, filename + 7 * sizeof(char), 10);
} else {
itoa(i, filename + 6 * sizeof(char), 10);
}
filename[8] = '.'; //clear null termination from itoa
if (!(SD.exists(filename))) {
Serial.print("inside: ");
Serial.println(filename);
break;
}
}
}
inside: FLIGHT04.csv
outside:
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment