Use SD card from Aitendo TFT 2.2 display.

Dependencies:   SDFileSystem mbed ILI9340_Driver_Lib

Fork of Seeed_SDCard_Shield by Shields

Revision:
7:161ee1b5617b
Parent:
3:5edc67dee8b7
Child:
8:a81a5af65446
--- a/main.cpp	Sun Apr 12 12:49:55 2015 +0000
+++ b/main.cpp	Sun Apr 12 13:16:05 2015 +0000
@@ -1,45 +1,117 @@
-/* Copyright (c) 2010-2011 mbed.org, MIT License
-*
-* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
-* and associated documentation files (the "Software"), to deal in the Software without
-* restriction, including without limitation the rights to use, copy, modify, merge, publish,
-* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
-* Software is furnished to do so, subject to the following conditions:
-*
-* The above copyright notice and this permission notice shall be included in all copies or
-* substantial portions of the Software.
-*
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
-* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
-* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-*/
+
 
 #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() {
-    wait(2);
-    pc.printf("Initializing\r\n");
+
+    // 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;
     
-    fp = fopen("/sd/hello.txt", "r");
-    if (fp != NULL) {
+    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);
-        remove("/sd/hello.txt");
-        pc.printf("Remove an existing file with the same name\r\n");
-    }
-    
-    fp = fopen("/sd/hello.txt", "w");
-    if (fp == NULL) {
-        pc.printf("Unable to write the file\r\n");
-    } else {
-        fprintf(fp, "mbed SDCard application!");
-        fclose(fp);
-        pc.printf("File successfully written!\r\n");
+        //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);
+        
     }
 }