TS Eyes A simple program to test TSI function of FRDM-KL25Z board using the Adafruit 2.8" TFT with Touch Sensor. It behaves like the X11eyes, but this time it follows the point where the TSI sensor is being touched. When the right most edge of the TSI is touched, the program exits the loop and pretend to be sleeping. By touching TFT display, program resume to the staring eye loop.

Dependencies:   SPI_STMPE610 SPI_TFT_ILI9341 TFT_fonts TSI mbed

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 "TSISensor.h"
00022 #include "SPI_TFT_ILI9341.h"
00023 #include "SPI_STMPE610.h"
00024 #include "Arial12x12.h"
00025 #include "Arial24x23.h"
00026 #include "Arial28x28.h"
00027 #include "font_big.h"
00028 
00029 #define PIN_MOSI        PTD2
00030 #define PIN_MISO        PTD3 
00031 #define PIN_SCLK        PTD1 
00032 #define PIN_CS_TFT      PTD0 
00033 #define PIN_DC_TFT      PTD5 
00034 #define PIN_BL_TFT      PTC9 
00035 #define PIN_CS_SD       PTA4 
00036 #define PIN_CS_TSC      PTA13
00037 #define PIN_TSC_INTR    PTC9
00038 
00039 TSISensor tsi;
00040 
00041 SPI_TFT_ILI9341 TFT(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TFT, PIN_BL_TFT, PIN_DC_TFT) ;
00042 SPI_STMPE610 TSC(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TSC) ;
00043 
00044 DigitalOut backlight(PTA12) ;
00045 
00046 void initTFT(void)
00047 {
00048     //Configure the display driver
00049     TFT.background(Black);
00050     TFT.foreground(White);
00051     wait(0.01) ;
00052     TFT.cls();
00053 }
00054 
00055 void moveEyes(void)
00056 {
00057     int dx, px ;
00058     float delta = 0.0 ;
00059     dx = 0 ;
00060     px = 0 ;
00061     backlight = 0 ;
00062     TFT.background(Black);
00063     wait(0.1) ;
00064     TFT.foreground(White);
00065     wait(0.1) ;
00066     TFT.cls() ;
00067     wait(0.1) ;
00068 
00069     TFT.set_font((unsigned char*) Arial12x12);
00070     TFT.foreground(Blue) ;
00071     TFT.locate(60, 10) ;
00072     TFT.printf("<< TS Eyes >>") ;
00073     TFT.locate(30, 280) ;
00074     TFT.printf("Use FRDM touch slider") ;
00075     TFT.locate(30, 300) ;
00076     TFT.printf("Touch right edge to end") ;
00077     
00078     TFT.fillcircle(120, 160, 100, Green) ;
00079     TFT.fillcircle(60, 160, 50, Black) ;
00080     TFT.fillcircle(60, 160, 45, White) ;
00081     TFT.fillcircle(180, 160, 50, Black) ;
00082     TFT.fillcircle(180, 160, 45, White) ;
00083     TFT.fillcircle(60, 160, 5, Black) ;
00084     TFT.fillcircle(180, 160, 5, Black) ;
00085     backlight = 1 ;
00086 
00087     while(dx < 38) {
00088       delta = (80.0 * (tsi.readPercentage()-0.5)) ;
00089       dx = (int)(delta + 0.5) ;
00090       TFT.fillcircle(60+px, 160, 5, White) ;
00091       TFT.fillcircle(180+px, 160, 5, White) ;
00092       TFT.fillcircle(60+dx, 160, 5, Black) ;
00093       TFT.fillcircle(180+dx, 160, 5, Black) ;
00094       px = dx ;
00095       wait(0.1) ;
00096     }
00097     TFT.fillcircle(60+px, 160, 5, White) ;
00098     TFT.fillcircle(180+px, 160, 5, White) ;
00099     TFT.line(15, 160, 105, 160, Black) ;
00100     TFT.line(135, 160, 225, 160, Black) ;
00101     TFT.locate(30, 280) ;
00102     TFT.printf("    Sleeping ... zzz     ") ;
00103     TFT.locate(20, 300) ;
00104     TFT.foreground(Yellow) ;
00105     TFT.printf("  Touch TFT to wake up") ;
00106 }
00107     
00108 int main()
00109 {
00110     uint16_t x, y, z ;
00111     bool awake = true ;
00112     
00113     initTFT() ;
00114     
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 }