STS2 Adafruit TFT ok

Dependencies:   SPI_STMPE610 SPI_TFT_ILI9341 TFT_fonts mbed

Fork of TS_Eyes by Motoo Tanaka

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /** TS_Eyes TSI sample program using Adafruit 2.8" TFT with Touch
00002  *
00003  * @note Just like the good old X11 eyes
00004  * @note this program stares at the point where
00005  * @note the TSI sensor of FRDM is being touched.
00006  * @note By touching the right most side of the sensor
00007  * @note program exits the staring loop and pretend to sleep.
00008  * @note Then touching the TFT starts the staring loop again.
00009  */
00010 
00011 /*
00012  * Note: This program is derived from the SeeeStudioTFTv2 program.
00013  * Although both program share same ILI9341 TFT driver,
00014  * the touch sensor was not same with the Display I purchased from Akizuki.
00015  * http://akizukidenshi.com/catalog/g/gM-07747/
00016  * The touch sensor on the display is STMPE610,
00017  * so I hacked the minimum spi driver for it (polling mode only).
00018  */
00019 
00020 #include "mbed.h"
00021 #include "SPI_TFT_ILI9341.h"
00022 //#include "SPI_STMPE610.h"
00023 #include "Arial12x12.h"
00024 #include "Arial24x23.h"
00025 #include "Arial28x28.h"
00026 #include "font_big.h"
00027 
00028 #define PIN_MOSI        p5
00029 #define PIN_MISO        p6
00030 #define PIN_SCLK        p7
00031 #define PIN_CS_TFT      p8
00032 #define PIN_RESET_TFT   p9
00033 #define PIN_DC_TFT      p10
00034 #define PIN_LIGHT_TFT      p21
00035 #define PIN_CS_SD p11
00036 
00037 
00038 SPI_TFT_ILI9341 TFT(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TFT, PIN_RESET_TFT, PIN_DC_TFT) ;
00039 
00040 DigitalOut backlight(PIN_LIGHT_TFT) ;
00041 DigitalOut CS_SD(PIN_CS_SD);
00042 void initTFT(void)
00043 {
00044     CS_SD = 1;
00045     //Configure the display driver
00046     TFT.background(Blue);
00047     TFT.foreground(White);
00048     wait(0.01) ;
00049     TFT.cls();
00050     TFT.set_orientation(1);  
00051 }
00052 
00053 void moveEyes(void)
00054 {
00055 //    int dx, px ;
00056 //    float delta = 0.0 ;
00057  //   dx = 0 ;
00058  //   px = 0 ;
00059  //   backlight = 0 ;
00060     TFT.background(Blue);
00061     wait(0.1) ;
00062     TFT.foreground(White);
00063     wait(0.1) ;
00064     TFT.cls() ;
00065     wait(0.1) ;
00066 
00067     TFT.set_font((unsigned char*) Arial12x12);
00068     TFT.foreground(Red) ;
00069     TFT.locate(60, 10) ;
00070     TFT.printf("<< TS Eyes >>") ;
00071     TFT.locate(30, 280) ;
00072     TFT.printf("Use FRDM touch slider") ;
00073     TFT.locate(30, 300) ;
00074     TFT.printf("Touch right edge to end") ;
00075 
00076     TFT.fillcircle(120, 160, 100, Green) ;
00077     TFT.fillcircle(60, 160, 50, Black) ;
00078     TFT.fillcircle(60, 160, 45, White) ;
00079     TFT.fillcircle(180, 160, 50, Black) ;
00080     TFT.fillcircle(180, 160, 45, White) ;
00081     TFT.fillcircle(60, 160, 5, Black) ;
00082     TFT.fillcircle(180, 160, 5, Black) ;
00083     backlight = 1 ;
00084 
00085     /*  while(dx < 38) {
00086      //   delta = (80.0 * (tsi.readPercentage()-0.5)) ;
00087         dx = (int)(delta + 0.5) ;
00088         TFT.fillcircle(60+px, 160, 5, White) ;
00089         TFT.fillcircle(180+px, 160, 5, White) ;
00090         TFT.fillcircle(60+dx, 160, 5, Black) ;
00091         TFT.fillcircle(180+dx, 160, 5, Black) ;
00092         px = dx ;
00093         wait(0.1) ;
00094       }
00095     TFT.fillcircle(60+px, 160, 5, White) ;
00096     TFT.fillcircle(180+px, 160, 5, White) ;*/
00097     TFT.line(15, 160, 105, 160, Black) ;
00098     TFT.line(135, 160, 225, 160, Black) ;
00099     TFT.locate(30, 280) ;
00100     TFT.printf("    Sleeping ... zzz     ") ;
00101     TFT.locate(20, 300) ;
00102     TFT.foreground(Yellow) ;
00103     TFT.printf("  Touch TFT to wake up") ;
00104 }
00105 
00106 int main()
00107 {
00108 //    uint16_t x, y, z ;
00109 //    bool awake = true ;
00110 
00111     backlight = 0 ;   
00112     initTFT() ;
00113     backlight = 1 ;   
00114     moveEyes() ;
00115     for(;;) {
00116 
00117         /*       if (awake) {
00118                   moveEyes() ;
00119                    awake = false ;
00120                }*/
00121 
00122         /*      if ( TSC.getRAWPoint(&x, &y, &z)) {
00123                   awake = true ;
00124               }
00125               */
00126     }
00127 }