Use SD card from Aitendo TFT 2.2 display.
Dependencies: SDFileSystem mbed ILI9340_Driver_Lib
Fork of Seeed_SDCard_Shield by
main.cpp
- Committer:
- ImageWriter
- Date:
- 2015-04-12
- Revision:
- 7:161ee1b5617b
- Parent:
- 3:5edc67dee8b7
- Child:
- 8:a81a5af65446
File content as of revision 7:161ee1b5617b:
#include "mbed.h" #include "SDFileSystem.h" #include "ILI9340_Driver.h" Serial pc(USBTX, USBRX); SDFileSystem sd(D11, D12, D13, D10, "sd"); // MOSI, MISO, SCK, CS FILE *fp; int main() { // create the display object // Nucleo-F411RE to M-TM022-SPI(Aitendo) connection. // 2014.12.30 ImageWriter // ------------------------------------------------ // [Nucleo] [M-TM022-SPI] // (D2) --- Reset; // (D4) --- CS; // (D7) --- D/C; // (D13) --- CLK; // (D11) --- MOSI; // (D12) --- MISO; // (3V3) --- VCC; // (3V3) -R- LED; (R=220 to 330 ohm) // (GND) --- GND // (A1) --- LM35DZ (IC tempture sensor 10mV/deg C ) ILI9340_Display myTft = ILI9340_Display(D11, D12, D13, D4, D2, D7); // create the Analog object AnalogIn myA1(A1); // initialise the display myTft.DispInit(); // clears the screen to remove all noise data myTft.FillScreen(ILI9340_WHITE); // set up variables char roomTemptureString[] = "0000"; char roomTemptureString_old[] = "0000"; int roomTempture; // Room Tempture * 100 long realTempture; // For calucrate int xx = 1; while(true) { realTempture = 0; for(int i=0;i<1000;i++){ realTempture += myA1.read_u16()*33000/65535; // realTemp = 3300mv * 10 / 0xFFFF } realTempture = realTempture/1000; roomTempture = int(realTempture); // Cast int //myTft.FillScreen(ILI9340_WHITE); myTft.DrawString("Now room tempture is",30,10,1,ILI9340_BLACK); myTft.IntToChars(roomTemptureString,roomTempture,4,10,9999,9999,3,ILI9340_BLACK); // offscreen write // Erace old charactor myTft.DrawAscii(roomTemptureString_old[0],10, 50,3,ILI9340_WHITE); myTft.DrawAscii(roomTemptureString_old[1],30, 50,3,ILI9340_WHITE); //myTft.DrawAscii('.' ,50, 50,3,ILI9340_WHITE); myTft.DrawAscii(roomTemptureString_old[2],70, 50,3,ILI9340_WHITE); myTft.DrawAscii(roomTemptureString_old[3],90, 50,3,ILI9340_WHITE); //myTft.DrawString("deg C" ,110,50,3,ILI9340_WHITE); // Erase new charactor myTft.DrawAscii(roomTemptureString[0],10, 50,3,ILI9340_BLACK); myTft.DrawAscii(roomTemptureString[1],30, 50,3,ILI9340_BLACK); myTft.DrawAscii('.' ,50, 50,3,ILI9340_BLACK); myTft.DrawAscii(roomTemptureString[2],70, 50,3,ILI9340_BLACK); myTft.DrawAscii(roomTemptureString[3],90, 50,3,ILI9340_BLACK); myTft.DrawString("deg C" ,110,50,3,ILI9340_BLACK); // xx counter if(xx > 239){ xx=1; }else{ xx++; } // Erese old plot myTft.DrawLine(xx,319,xx,(319 - 5000/25) ,ILI9340_WHITE); // Draw scale line myTft.DrawLine(0,319-1000/25,240,319-1000/25,ILI9340_BLACK); myTft.DrawLine(0,319-2000/25,240,319-2000/25,ILI9340_BLACK); myTft.DrawLine(0,319-3000/25,240,319-3000/25,ILI9340_BLACK); myTft.DrawLine(0,319-4000/25,240,319-4000/25,ILI9340_BLACK); // plot graph myTft.DrawLine(xx,(317 - roomTempture/25),xx,(319 - roomTempture/25),ILI9340_BLACK); // cursor myTft.DrawLine(xx,319,xx,309,ILI9340_BLACK); // logger fp = fopen("/sd/mylogger.txt", "a+"); if (fp == NULL) { pc.printf("Unable to write the file\r\n"); } else { pc.printf("%d \r\n",roomTempture); fprintf(fp, "%d \r\n",roomTempture); } fclose(fp); //pc.printf("File successfully written!\r\n"); wait(10); // erace cursor myTft.DrawLine(xx,319,xx,309,ILI9340_WHITE); // save old character strcpy(roomTemptureString_old,roomTemptureString); } }