Hi, i have problem with function in cycle. This is my code:
#include <SD.h>
File root;
const int chipSelect = 4;
void setup()
{
Serial.begin(9600);
pinMode(10, OUTPUT);
if (!SD.begin(4)) {
Serial.println("Failed to configure SD card");
return;
}
}
void loop()
{
printDirectory();
delay (3000);
createfile("something.txt");
delay(3000);
printDirectory();
delay (3000);
}
void printDirectory() {
root = SD.open("/");
while(true) {
File entry = root.openNextFile();
if (! entry) {
root.rewindDirectory();
root.close();
break;
}
Serial.println(entry.name());
entry.close();
}
}
void createfile(char *myfile)
{
Serial.println("file creating...");
if (SD.exists(myfile)) {
Serial.println("but exist.");
}
else {
root = SD.open(myfile, FILE_WRITE);
root.close();
Serial.println("created.");
}
}
So, when im start procces after reset, only first printDirectory on loop show file list on sd root corectly. After that i use createfile like second function on loop, then third printDirectory cant show file list. And after that all printDirectory cant show file list. In this case help only reset button. Can you help mi someone with this ? Thanks