#include <SD.h>
void readfile() {
File test3 = SD.open("/testfile.txt", "r");
while (test3.available()) {
Serial.write(test3.read());
}
test3.close();
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32-S3!");
SPI.begin(8, 17, 46, 9);
SD.begin(9);
Serial.printf("card size: %d\n", SD.cardSize());
Serial.println("\ntest1");
File test1 = SD.open("/testfile.txt","a");
test1.print("this is test content!\n");
test1.close();
readfile();
Serial.println("\ntest2");
File test2 = SD.open("/testfile.txt", "a");
test2.seek(0, SeekEnd);
test2.write((const uint8_t*)"that", 4);
test2.close();
readfile();
Serial.println("\ntest3");
FILE* f;
f = fopen("/sd/testfile.txt", "a");
const char* newtext = "thus";
fseek(f, 0, SeekEnd);
fwrite(newtext, sizeof(char), 4, f);
fclose(f);
readfile();
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}