以下代码测试TFT显示正常,sd卡中的txt文件也能正常读取。
只是有个函数readID返回值有误,可能是控制芯片的原因?- #include <TFTv2.h>
- #include <SPI.h>
- #include <SD.h>
- const int chipSelect = 8;
- void setup()
- {
- // Open serial communications and wait for port to open:
- Serial.begin(9600);
- Serial.print("Initializing SD card...");
- // make sure that the default chip select pin is set to
- // output, even if you don't use it:
- pinMode(10, OUTPUT);
-
- // see if the card is present and can be initialized:
- if (!SD.begin(chipSelect)) {
- Serial.println("Card failed, or not present");
- // don't do anything more:
- return;
- }
- Serial.println("card initialized.");
-
- // open the file. note that only one file can be open at a time,
- // so you have to close this one before opening another.
- File dataFile = SD.open("Textfile.txt");
- // if the file is available, write to it:
- if (dataFile)
- {
- while (dataFile.available()) {
- Serial.write(dataFile.read());
- }
- }
- // if the file isn't open, pop up an error:
- else {
- Serial.println("error opening datalog.txt");
- }
- TFT_BL_ON; // turn on the background light
- Tft.TFTinit(); // init TFT library
-
- Tft.drawChar('S',0,0,1,RED); // draw char: 'S', (0, 0), size: 1, color: RED
-
- Tft.drawChar('E',10,10,2,BLUE); // draw char: 'E', (10, 10), size: 2, color: BLUE
-
- Tft.drawChar('E',20,40,3,GREEN); // draw char: 'E', (20, 40), size: 3, color: GREEN
-
- Tft.drawChar('E',30,80,4,YELLOW); // draw char: 'E', (30, 80), size: 4, color: YELLOW
-
- Tft.drawChar('D',40,120,4,YELLOW); // draw char: 'D', (40, 120), size: 4, color: YELLOW
-
- Tft.drawString("Hello",0,180,3,CYAN); // draw string: "hello", (0, 180), size: 3, color: CYAN
-
- Tft.drawString("World!!",60,220,4,WHITE); // draw string: "world!!", (80, 230), size: 4, color: WHITE
-
- dataFile.close();
-
- }
- void loop()
- {
- }
复制代码 |