STS2 Adafruit TFT ok
Dependencies: SPI_STMPE610 SPI_TFT_ILI9341 TFT_fonts mbed
Fork of TS_Eyes by
main.cpp@2:344ee4288dd7, 2015-03-24 (annotated)
- Committer:
- schnf30
- Date:
- Tue Mar 24 09:36:20 2015 +0000
- Revision:
- 2:344ee4288dd7
- Parent:
- 1:7cc0446656ae
TFT Adafruit fonctionne
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Rhyme | 1:7cc0446656ae | 1 | /** TS_Eyes TSI sample program using Adafruit 2.8" TFT with Touch |
Rhyme | 0:0b7a110bfceb | 2 | * |
Rhyme | 0:0b7a110bfceb | 3 | * @note Just like the good old X11 eyes |
Rhyme | 0:0b7a110bfceb | 4 | * @note this program stares at the point where |
Rhyme | 0:0b7a110bfceb | 5 | * @note the TSI sensor of FRDM is being touched. |
Rhyme | 0:0b7a110bfceb | 6 | * @note By touching the right most side of the sensor |
Rhyme | 0:0b7a110bfceb | 7 | * @note program exits the staring loop and pretend to sleep. |
Rhyme | 0:0b7a110bfceb | 8 | * @note Then touching the TFT starts the staring loop again. |
Rhyme | 0:0b7a110bfceb | 9 | */ |
schnf30 | 2:344ee4288dd7 | 10 | |
schnf30 | 2:344ee4288dd7 | 11 | /* |
schnf30 | 2:344ee4288dd7 | 12 | * Note: This program is derived from the SeeeStudioTFTv2 program. |
schnf30 | 2:344ee4288dd7 | 13 | * Although both program share same ILI9341 TFT driver, |
schnf30 | 2:344ee4288dd7 | 14 | * the touch sensor was not same with the Display I purchased from Akizuki. |
schnf30 | 2:344ee4288dd7 | 15 | * http://akizukidenshi.com/catalog/g/gM-07747/ |
schnf30 | 2:344ee4288dd7 | 16 | * The touch sensor on the display is STMPE610, |
schnf30 | 2:344ee4288dd7 | 17 | * so I hacked the minimum spi driver for it (polling mode only). |
schnf30 | 2:344ee4288dd7 | 18 | */ |
Rhyme | 0:0b7a110bfceb | 19 | |
Rhyme | 0:0b7a110bfceb | 20 | #include "mbed.h" |
Rhyme | 0:0b7a110bfceb | 21 | #include "SPI_TFT_ILI9341.h" |
schnf30 | 2:344ee4288dd7 | 22 | //#include "SPI_STMPE610.h" |
Rhyme | 0:0b7a110bfceb | 23 | #include "Arial12x12.h" |
Rhyme | 0:0b7a110bfceb | 24 | #include "Arial24x23.h" |
Rhyme | 0:0b7a110bfceb | 25 | #include "Arial28x28.h" |
Rhyme | 0:0b7a110bfceb | 26 | #include "font_big.h" |
Rhyme | 0:0b7a110bfceb | 27 | |
schnf30 | 2:344ee4288dd7 | 28 | #define PIN_MOSI p5 |
schnf30 | 2:344ee4288dd7 | 29 | #define PIN_MISO p6 |
schnf30 | 2:344ee4288dd7 | 30 | #define PIN_SCLK p7 |
schnf30 | 2:344ee4288dd7 | 31 | #define PIN_CS_TFT p8 |
schnf30 | 2:344ee4288dd7 | 32 | #define PIN_RESET_TFT p9 |
schnf30 | 2:344ee4288dd7 | 33 | #define PIN_DC_TFT p10 |
schnf30 | 2:344ee4288dd7 | 34 | #define PIN_LIGHT_TFT p21 |
schnf30 | 2:344ee4288dd7 | 35 | #define PIN_CS_SD p11 |
Rhyme | 0:0b7a110bfceb | 36 | |
schnf30 | 2:344ee4288dd7 | 37 | |
schnf30 | 2:344ee4288dd7 | 38 | SPI_TFT_ILI9341 TFT(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TFT, PIN_RESET_TFT, PIN_DC_TFT) ; |
Rhyme | 0:0b7a110bfceb | 39 | |
schnf30 | 2:344ee4288dd7 | 40 | DigitalOut backlight(PIN_LIGHT_TFT) ; |
schnf30 | 2:344ee4288dd7 | 41 | DigitalOut CS_SD(PIN_CS_SD); |
Rhyme | 0:0b7a110bfceb | 42 | void initTFT(void) |
Rhyme | 0:0b7a110bfceb | 43 | { |
schnf30 | 2:344ee4288dd7 | 44 | CS_SD = 1; |
Rhyme | 0:0b7a110bfceb | 45 | //Configure the display driver |
schnf30 | 2:344ee4288dd7 | 46 | TFT.background(Blue); |
Rhyme | 0:0b7a110bfceb | 47 | TFT.foreground(White); |
Rhyme | 0:0b7a110bfceb | 48 | wait(0.01) ; |
Rhyme | 0:0b7a110bfceb | 49 | TFT.cls(); |
schnf30 | 2:344ee4288dd7 | 50 | TFT.set_orientation(1); |
Rhyme | 0:0b7a110bfceb | 51 | } |
Rhyme | 0:0b7a110bfceb | 52 | |
Rhyme | 1:7cc0446656ae | 53 | void moveEyes(void) |
Rhyme | 0:0b7a110bfceb | 54 | { |
schnf30 | 2:344ee4288dd7 | 55 | // int dx, px ; |
schnf30 | 2:344ee4288dd7 | 56 | // float delta = 0.0 ; |
schnf30 | 2:344ee4288dd7 | 57 | // dx = 0 ; |
schnf30 | 2:344ee4288dd7 | 58 | // px = 0 ; |
schnf30 | 2:344ee4288dd7 | 59 | // backlight = 0 ; |
schnf30 | 2:344ee4288dd7 | 60 | TFT.background(Blue); |
Rhyme | 0:0b7a110bfceb | 61 | wait(0.1) ; |
Rhyme | 0:0b7a110bfceb | 62 | TFT.foreground(White); |
Rhyme | 0:0b7a110bfceb | 63 | wait(0.1) ; |
Rhyme | 0:0b7a110bfceb | 64 | TFT.cls() ; |
Rhyme | 0:0b7a110bfceb | 65 | wait(0.1) ; |
Rhyme | 0:0b7a110bfceb | 66 | |
Rhyme | 0:0b7a110bfceb | 67 | TFT.set_font((unsigned char*) Arial12x12); |
schnf30 | 2:344ee4288dd7 | 68 | TFT.foreground(Red) ; |
Rhyme | 0:0b7a110bfceb | 69 | TFT.locate(60, 10) ; |
Rhyme | 1:7cc0446656ae | 70 | TFT.printf("<< TS Eyes >>") ; |
Rhyme | 0:0b7a110bfceb | 71 | TFT.locate(30, 280) ; |
Rhyme | 0:0b7a110bfceb | 72 | TFT.printf("Use FRDM touch slider") ; |
Rhyme | 0:0b7a110bfceb | 73 | TFT.locate(30, 300) ; |
Rhyme | 0:0b7a110bfceb | 74 | TFT.printf("Touch right edge to end") ; |
schnf30 | 2:344ee4288dd7 | 75 | |
Rhyme | 0:0b7a110bfceb | 76 | TFT.fillcircle(120, 160, 100, Green) ; |
Rhyme | 0:0b7a110bfceb | 77 | TFT.fillcircle(60, 160, 50, Black) ; |
Rhyme | 0:0b7a110bfceb | 78 | TFT.fillcircle(60, 160, 45, White) ; |
Rhyme | 0:0b7a110bfceb | 79 | TFT.fillcircle(180, 160, 50, Black) ; |
Rhyme | 0:0b7a110bfceb | 80 | TFT.fillcircle(180, 160, 45, White) ; |
Rhyme | 0:0b7a110bfceb | 81 | TFT.fillcircle(60, 160, 5, Black) ; |
Rhyme | 0:0b7a110bfceb | 82 | TFT.fillcircle(180, 160, 5, Black) ; |
Rhyme | 0:0b7a110bfceb | 83 | backlight = 1 ; |
Rhyme | 0:0b7a110bfceb | 84 | |
schnf30 | 2:344ee4288dd7 | 85 | /* while(dx < 38) { |
schnf30 | 2:344ee4288dd7 | 86 | // delta = (80.0 * (tsi.readPercentage()-0.5)) ; |
schnf30 | 2:344ee4288dd7 | 87 | dx = (int)(delta + 0.5) ; |
schnf30 | 2:344ee4288dd7 | 88 | TFT.fillcircle(60+px, 160, 5, White) ; |
schnf30 | 2:344ee4288dd7 | 89 | TFT.fillcircle(180+px, 160, 5, White) ; |
schnf30 | 2:344ee4288dd7 | 90 | TFT.fillcircle(60+dx, 160, 5, Black) ; |
schnf30 | 2:344ee4288dd7 | 91 | TFT.fillcircle(180+dx, 160, 5, Black) ; |
schnf30 | 2:344ee4288dd7 | 92 | px = dx ; |
schnf30 | 2:344ee4288dd7 | 93 | wait(0.1) ; |
schnf30 | 2:344ee4288dd7 | 94 | } |
Rhyme | 0:0b7a110bfceb | 95 | TFT.fillcircle(60+px, 160, 5, White) ; |
schnf30 | 2:344ee4288dd7 | 96 | TFT.fillcircle(180+px, 160, 5, White) ;*/ |
Rhyme | 0:0b7a110bfceb | 97 | TFT.line(15, 160, 105, 160, Black) ; |
Rhyme | 0:0b7a110bfceb | 98 | TFT.line(135, 160, 225, 160, Black) ; |
Rhyme | 0:0b7a110bfceb | 99 | TFT.locate(30, 280) ; |
Rhyme | 0:0b7a110bfceb | 100 | TFT.printf(" Sleeping ... zzz ") ; |
Rhyme | 0:0b7a110bfceb | 101 | TFT.locate(20, 300) ; |
Rhyme | 0:0b7a110bfceb | 102 | TFT.foreground(Yellow) ; |
Rhyme | 0:0b7a110bfceb | 103 | TFT.printf(" Touch TFT to wake up") ; |
Rhyme | 0:0b7a110bfceb | 104 | } |
schnf30 | 2:344ee4288dd7 | 105 | |
Rhyme | 0:0b7a110bfceb | 106 | int main() |
Rhyme | 0:0b7a110bfceb | 107 | { |
schnf30 | 2:344ee4288dd7 | 108 | // uint16_t x, y, z ; |
schnf30 | 2:344ee4288dd7 | 109 | // bool awake = true ; |
schnf30 | 2:344ee4288dd7 | 110 | |
schnf30 | 2:344ee4288dd7 | 111 | backlight = 0 ; |
Rhyme | 0:0b7a110bfceb | 112 | initTFT() ; |
schnf30 | 2:344ee4288dd7 | 113 | backlight = 1 ; |
schnf30 | 2:344ee4288dd7 | 114 | moveEyes() ; |
Rhyme | 0:0b7a110bfceb | 115 | for(;;) { |
Rhyme | 0:0b7a110bfceb | 116 | |
schnf30 | 2:344ee4288dd7 | 117 | /* if (awake) { |
schnf30 | 2:344ee4288dd7 | 118 | moveEyes() ; |
schnf30 | 2:344ee4288dd7 | 119 | awake = false ; |
schnf30 | 2:344ee4288dd7 | 120 | }*/ |
schnf30 | 2:344ee4288dd7 | 121 | |
schnf30 | 2:344ee4288dd7 | 122 | /* if ( TSC.getRAWPoint(&x, &y, &z)) { |
schnf30 | 2:344ee4288dd7 | 123 | awake = true ; |
schnf30 | 2:344ee4288dd7 | 124 | } |
schnf30 | 2:344ee4288dd7 | 125 | */ |
Rhyme | 0:0b7a110bfceb | 126 | } |
Rhyme | 0:0b7a110bfceb | 127 | } |