#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <SdFat.h>
#include <Adafruit_ImageReader.h>
#define SD_CS 4 // SD card select pin
#define TFT_CS 10 // TFT select pin
#define TFT_DC 8 // TFT display/command pin
#define TFT_RST 9 // TFT reset pin
SdFat SD;
SdFile myFile;
Adafruit_ImageReader reader(SD);
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
Adafruit_Image img;
void setup(void) {
Serial.begin(9600);
tft.begin(); // Initialize screen
Serial.print("Setup filesystem...");
if( !SD.begin( SD_CS, SD_SCK_MHZ(25) ) ) {
Serial.println("SD begin() failed");
while (1) ;
}
Serial.println("OK!");
tft.setRotation(3);
Serial.print("Loading wokwi.bmp to screen...");
//reader.printStatus( reader.drawBMP("/wokwi.bmp", tft, 0, 0) );
if (!myFile.open("test.txt", O_RDWR | O_CREAT | O_AT_END)) {
SD.errorHalt("opening test.txt for write failed");
}
myFile.println("testing 1, 2, 3.");
// close the file:
myFile.close();
// re-open the file for reading:
if (!myFile.open("test.txt", O_READ)) {
SD.errorHalt("opening test.txt for read failed");
}
Serial.println("test.txt:");
// read from the file until there's nothing else in it:
int data;
while ((data = myFile.read()) >= 0) Serial.write(data);
// close the file:
myFile.close();
}
void loop() {
}