#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <SD.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
#define MAX_Y 300
File f;
int char_height, y;
String filename;
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
void setup(void) {
Serial.begin(9600);
tft.begin(); // Initialize screen
Serial.print("Setup filesystem...");
if( !SD.begin( SD_CS ) ) {
Serial.println("SD begin() failed");
while (1) ;
}
Serial.println("OK!");
tft.setRotation(0);
tft.setTextSize(2);
tft.setCursor(0,0); tft.println(); char_height = tft.getCursorY();
Serial.println( char_height );
show_files();
delay(1000);
f = SD.open("text.txt");
if ( f ) {
show_one_page();
f.close();
}
else {
Serial.println("File not found!");
}
}
void show_files(){
tft.fillScreen( ILI9341_BLACK );
tft.setCursor(0,0);
tft.setTextSize(3);
File dir = SD.open("/");
while (1) {
File fff = dir.openNextFile();
if ( fff == 0 ) break;
tft.println( fff.name() );
filename = fff.name();
}
f.close();
tft.setTextSize(2);
Serial.println( filename );
}
void show_one_page() {
tft.fillScreen( ILI9341_BLACK );
tft.setCursor(0,0);
y = 0;
while ( f.available() > 0 && y < MAX_Y ) {
char ch = f.read();
Serial.write( ch );
tft.write(ch);
y = tft.getCursorY();
}
Serial.print("y="); Serial.println(y);
}
void loop() {
}