Simple test program for FRDM-KL25Z and Adafruit 2.8" TFT display. For the touch sensor, only polling mode is implemented.

Dependencies:   MMA8451Q SPI_STMPE610 TSI UniGraphic mbed

This program was to test Adafruit 2.8" TFT with touch with FRDM-KL25Z.
After download the binary to the FRDM-KL25Z and push the reset button ,
a simple welcome message will be displayed.

このプログラムは私が秋月で購入した Adafruit 2.8" TFT
http://akizukidenshi.com/catalog/g/gM-07747/
をFRDM-KL25Z で試すために書いたものです。
ダウンロード後にFRDM-KL25Zのリセットスイッチを押すと
最初の画面が表示されます。

Now using UniGraphic library.
And the problem of remaining previous screen is gone. ;-)
For a little bonus, TS_Eyes and Maze are also included.

UniGraphic ライブラリ版になり、画面にごみが残るバグが治りました。
おまけに TS_Eyes と Maze も追加してあります。 (^ ^)v

/media/uploads/Rhyme/img_0984_ss.jpg

If you push and keep the right side of the screen,
the screen will advance to the page2, which is a simple graph sample.

ここで画面の右側をしばらく押していると、次のページに移行します。
このページでは、簡単なグラフを表示する例を描画しています。

/media/uploads/Rhyme/img_0985_ss.jpg

And if you do the same again, the program advances to the page3,
which is a data display page of MMA8451Q accelerometer mounted on
the FRDM-KL25Z.

さらに画面の右側をしばらく押していると、次のページに移行します。
ここでは、FRDM-KL25Zに搭載されている MMA8451Q という3軸の
加速度センサの値を表示しています。

/media/uploads/Rhyme/img_0986_ss.jpg

And this is the last page of this program, so far, so if you
try to advance page, it will return to the first page.

このページが最後のページになっているので、さらにページ送りをすると
最初のページに戻ります。

Revision:
3:34d8706e1614
Parent:
1:39218b891bf3
--- a/main.cpp	Fri Oct 31 01:43:18 2014 +0000
+++ b/main.cpp	Sat Aug 08 12:07:56 2015 +0000
@@ -21,13 +21,14 @@
 
 #include "mbed.h"
 #include "MMA8451Q.h"
+#include "TSISensor.h"
 #include <math.h>
-#include "SPI_TFT_ILI9341.h"
+#include "ILI9341.h"
 #include "SPI_STMPE610.h"
 #include "Arial12x12.h"
 #include "Arial24x23.h"
 #include "Arial28x28.h"
-#include "font_big.h"
+#include "Arial43x48_numb.h"
 
 
 #define PIN_XP          PTB3
@@ -43,36 +44,46 @@
 #define PIN_CS_SD       PTA4 
 #define PIN_CS_TSC      PTA13
 #define PIN_TSC_INTR    PTC9
+#define PIN_RESET_TFT   PTB10
 
 #define MMA8451_I2C_ADDRESS (0x1d<<1)
 MMA8451Q *acc = 0 ;
+TSISensor tsi;
 
-//  SPI_TFT_ILI9341(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset, PinName dc, const char* name ="TFT");
-SPI_TFT_ILI9341 TFT(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TFT, PIN_BL_TFT, PIN_DC_TFT) ;
+DigitalOut backlight(PTA12) ;
+ILI9341 TFT(SPI_8, 10000000, 
+    PIN_MOSI, PIN_MISO,  PIN_SCLK, 
+    PIN_CS_TFT, PIN_RESET_TFT, PIN_DC_TFT, "Adafruit2.8") ;
 SPI_STMPE610 TSC(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TSC) ;
 
-DigitalOut backlight(PTA12) ;
 DigitalIn pinD7(PTC9) ;
 
 int page = 0 ;
-int numPage = 3 ;
+int numPage = 5 ;
+
+extern void doMaze(void) ;
 
 void initTFT(void)
 {
     //Configure the display driver
+    TFT.BusEnable(true) ;
+    TFT.FastWindow(true) ;
     TFT.background(Black);
     TFT.foreground(White);
     wait(0.01) ;
     TFT.cls();
+    TFT.BusEnable(false) ;
 }
 
 void screen1(void) // Welcome Screen
 {
+    TFT.BusEnable(true) ;
     backlight = 0 ;
     TFT.background(White) ;
+    wait(0.1) ;
     TFT.cls() ;
-
     wait(0.1) ;
+    
     TFT.set_font((unsigned char*) Arial24x23);
     TFT.foreground(Red) ;
     TFT.locate(80, 40) ;
@@ -85,19 +96,20 @@
     TFT.foreground(Black);
     TFT.set_font((unsigned char*) Arial12x12);
     TFT.foreground(Blue) ;
-    TFT.locate(10, 180) ;
+    TFT.locate(30, 180) ;
     TFT.printf("This program is running on") ;
-    TFT.locate(10, 200) ;
+    TFT.locate(30, 200) ;
     TFT.printf("freescale FRDM-KL25Z with") ;
-    TFT.locate(10, 220) ;
-    TFT.printf("a program developed on mbed") ;
+    TFT.locate(30, 220) ;
+    TFT.printf("a program developed in mbed") ;
     TFT.foreground(Green) ;
-    TFT.locate(10, 260) ;
+    TFT.locate(30, 260) ;
     TFT.printf("To advance demo page, touch") ;
-    TFT.locate(10, 280) ;
+    TFT.locate(30, 280) ;
     TFT.printf("and hold right side of screen") ;
-    TFT.locate(10, 300) ;
+    TFT.locate(30, 300) ;
     TFT.printf("until the next screen starts") ;
+    TFT.BusEnable(false) ;
     backlight = 1 ;
 }
 
@@ -106,10 +118,13 @@
     //Draw some graphics
     int i, x[2], y[2] ;
     backlight = 0 ;
-
+    TFT.BusEnable(true) ;
     TFT.background(Black);
+    wait(0.1) ;
     TFT.foreground(White);
+    wait(0.1) ;
     TFT.cls() ;
+    wait(0.1) ;
     TFT.set_font((unsigned char*) Arial12x12);
     TFT.locate(90,0);
     TFT.printf("Graphics");
@@ -150,6 +165,7 @@
     TFT.printf("simple graphics drawing") ;
     TFT.locate(20, 290) ;
     TFT.printf("capability is provided") ;
+    TFT.BusEnable(false) ;
     backlight = 1 ;
 }    
 
@@ -179,7 +195,8 @@
     unsigned short paneX[2] = {20, 235} ;
     unsigned short paneH = 81 ;
  
-    backlight = 0 ;
+    backlight = 1 ;
+    TFT.BusEnable(true) ;
     TFT.background(Black) ;
     TFT.foreground(White) ;
 //    TFT.cls() ;
@@ -233,6 +250,65 @@
         pt = t ;
         wait(0.01) ;
     }
+    TFT.BusEnable(false) ;
+}
+
+void screen4(void)
+{
+    int dx, px ;
+    float delta = 0.0 ;
+    dx = 0 ;
+    px = 0 ;
+    backlight = 0 ;
+    TFT.BusEnable(true) ;
+    TFT.background(Black);
+    wait(0.1) ;
+    TFT.foreground(White);
+    wait(0.1) ;
+    TFT.cls() ;
+    wait(0.1) ;
+
+    TFT.set_font((unsigned char*) Arial12x12);
+    TFT.foreground(Blue) ;
+    TFT.locate(60, 10) ;
+    TFT.printf("<< TSI demo >>") ;
+    TFT.locate(30, 280) ;
+    TFT.printf("Use FRDM touch slider") ;
+    TFT.locate(30, 300) ;
+    TFT.printf("Touch right edge to end") ;
+    
+    TFT.fillcircle(120, 160, 100, Green) ;
+    TFT.fillcircle(60, 160, 50, Black) ;
+    TFT.fillcircle(60, 160, 45, White) ;
+    TFT.fillcircle(180, 160, 50, Black) ;
+    TFT.fillcircle(180, 160, 45, White) ;
+    TFT.fillcircle(60, 160, 5, Black) ;
+    TFT.fillcircle(180, 160, 5, Black) ;
+    backlight = 1 ;
+
+    while(dx < 38) {
+      delta = (80.0 * (tsi.readPercentage()-0.5)) ;
+      dx = (int)(delta + 0.5) ;
+      TFT.fillcircle(60+px, 160, 5, White) ;
+      TFT.fillcircle(180+px, 160, 5, White) ;
+      TFT.fillcircle(60+dx, 160, 5, Black) ;
+      TFT.fillcircle(180+dx, 160, 5, Black) ;
+      px = dx ;
+      wait(0.1) ;
+    }
+    TFT.fillcircle(60+px, 160, 5, White) ;
+    TFT.fillcircle(180+px, 160, 5, White) ;
+    TFT.line(15, 160, 105, 160, Black) ;
+    TFT.line(135, 160, 225, 160, Black) ;
+    TFT.foreground(Yellow) ;
+    TFT.locate(30, 300) ;
+//    TFT.printf("Use FRDM touch slider") ;
+    TFT.printf("       Wake Up!          ") ;
+    TFT.locate(5, 300) ;
+    TFT.printf("<< Prev") ;
+    TFT.locate(180, 300) ;
+    TFT.printf("Next >>") ;
+    TFT.BusEnable(false) ;
 }
 
 void incPage(void)
@@ -254,13 +330,14 @@
 int main()
 {
     uint16_t x, y, z ;
-    int prevPage = 0 ;
+    int prevPage = 99 ;
+    bool waitTouch = false ;
     
     acc = new MMA8451Q(PTE25, PTE24, MMA8451_I2C_ADDRESS) ;
     
     initTFT() ;
     
-    screen1() ;
+ //   screen0() ;
         
     printf("Program Started!\n\r") ;
     
@@ -271,36 +348,54 @@
             if (prevPage != page) {
                 screen1() ;
             }
+            waitTouch = true ;
             break ;
         case 1:
             if (prevPage != page) {
                 screen2() ; 
             }
+            waitTouch = true ;
             break ;
         case 2:
             if (prevPage != page) {
+                TFT.BusEnable(true) ;
                 TFT.background(Black) ;
                 TFT.foreground(White) ;
                 TFT.cls() ;
+                TFT.BusEnable(false) ;
             }
             screen3() ; 
-            wait(2) ;
+            waitTouch = false ;
+            break ;
+        case 3:
+//            if (prevPage != page) {
+                screen4() ;
+                waitTouch = true ;
+//            }
+            break ;
+        case 4:
+//            if (prevPage != page) {
+                doMaze() ;
+                waitTouch = true ;
+//            }
             break ;
         default:
             page = 0 ; 
             break ;
         }
         prevPage = page ;
-        printf("Screen Printed\n\r") ;
 
-        TSC.getRAWPoint(&x, &y, &z) ;
-        if ((x != 0)||(y != 0) || (z != 0)) {
-            if (x < 1000) { // left
-                decPage() ;
-            } else if (x > 3000) { // right
-                incPage() ;
+        do {
+            TSC.getRAWPoint(&x, &y, &z) ;
+            if ((x != 0)||(y != 0) || (z != 0)) {
+                if (x < 1000) { // left
+                    decPage() ;
+                } else if (x > 3000) { // right
+                    incPage() ;
+                }
+                waitTouch = false ;
             }
-        }
+        } while(waitTouch != false) ;
 //        wait(1) ;
     }
 }