Demo program for Adafruit TFT 2.8" TFT resistive touch Shield - TFT screen library from SeeedStudio - touch screen library from Motoo Tanaka - pinout for Nucleo-F103RB
Dependencies: SPI_STMPE610 SeeedStudioTFTv2 TFT_fonts mbed
Fork of Seeed_TFT_Touch_Shield by
main.cpp@5:2682b8d7e871, 2015-04-03 (annotated)
- Committer:
- hcseran
- Date:
- Fri Apr 03 07:13:35 2015 +0000
- Revision:
- 5:2682b8d7e871
- Parent:
- 2:5c2f6ff36ff1
Demo program for Adafruit 2.8" TFT touch screen with Nucleo-F103RB
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lawliet | 1:b2794eb7c940 | 1 | /* |
lawliet | 1:b2794eb7c940 | 2 | main.cpp |
lawliet | 1:b2794eb7c940 | 3 | 2014 Copyright (c) Seeed Technology Inc. All right reserved. |
lawliet | 1:b2794eb7c940 | 4 | |
lawliet | 1:b2794eb7c940 | 5 | Author:lawliet zou(lawliet.zou@gmail.com) |
lawliet | 1:b2794eb7c940 | 6 | 2014-02-17 |
lawliet | 1:b2794eb7c940 | 7 | |
lawliet | 1:b2794eb7c940 | 8 | This library is free software; you can redistribute it and/or |
lawliet | 1:b2794eb7c940 | 9 | modify it under the terms of the GNU Lesser General Public |
lawliet | 1:b2794eb7c940 | 10 | License as published by the Free Software Foundation; either |
lawliet | 1:b2794eb7c940 | 11 | version 2.1 of the License, or (at your option) any later version. |
lawliet | 1:b2794eb7c940 | 12 | |
lawliet | 1:b2794eb7c940 | 13 | This library is distributed in the hope that it will be useful, |
lawliet | 1:b2794eb7c940 | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
lawliet | 1:b2794eb7c940 | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
lawliet | 1:b2794eb7c940 | 16 | Lesser General Public License for more details. |
lawliet | 1:b2794eb7c940 | 17 | |
lawliet | 1:b2794eb7c940 | 18 | You should have received a copy of the GNU Lesser General Public |
lawliet | 1:b2794eb7c940 | 19 | License along with this library; if not, write to the Free Software |
lawliet | 1:b2794eb7c940 | 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
lawliet | 1:b2794eb7c940 | 21 | */ |
lawliet | 1:b2794eb7c940 | 22 | |
neilt6 | 0:407dafce805d | 23 | #include "mbed.h" |
neilt6 | 0:407dafce805d | 24 | #include "SeeedStudioTFTv2.h" |
neilt6 | 0:407dafce805d | 25 | #include "Arial12x12.h" |
neilt6 | 0:407dafce805d | 26 | #include "Arial24x23.h" |
neilt6 | 0:407dafce805d | 27 | #include "Arial28x28.h" |
neilt6 | 0:407dafce805d | 28 | #include "font_big.h" |
hcseran | 5:2682b8d7e871 | 29 | #include "SPI_STMPE610.h" |
neilt6 | 0:407dafce805d | 30 | |
screamer | 2:5c2f6ff36ff1 | 31 | #define PIN_XP A3 |
screamer | 2:5c2f6ff36ff1 | 32 | #define PIN_XM A1 |
screamer | 2:5c2f6ff36ff1 | 33 | #define PIN_YP A2 |
screamer | 2:5c2f6ff36ff1 | 34 | #define PIN_YM A0 |
screamer | 2:5c2f6ff36ff1 | 35 | #define PIN_MOSI D11 |
screamer | 2:5c2f6ff36ff1 | 36 | #define PIN_MISO D12 |
screamer | 2:5c2f6ff36ff1 | 37 | #define PIN_SCLK D13 |
hcseran | 5:2682b8d7e871 | 38 | //#define PIN_CS_TFT D5 // for SEED |
hcseran | 5:2682b8d7e871 | 39 | #define PIN_CS_TFT D10 // for adafruit |
hcseran | 5:2682b8d7e871 | 40 | //#define PIN_DC_TFT D6 // for SEED |
hcseran | 5:2682b8d7e871 | 41 | #define PIN_DC_TFT D9 // for adafruit |
screamer | 2:5c2f6ff36ff1 | 42 | #define PIN_BL_TFT D7 |
screamer | 2:5c2f6ff36ff1 | 43 | #define PIN_CS_SD D4 |
hcseran | 5:2682b8d7e871 | 44 | #define PIN_CS_TSC D8 |
lawliet | 1:b2794eb7c940 | 45 | |
screamer | 2:5c2f6ff36ff1 | 46 | SeeedStudioTFTv2 TFT(PIN_XP, PIN_XM, PIN_YP, PIN_YM, PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TFT, PIN_DC_TFT, PIN_BL_TFT, PIN_CS_SD); |
hcseran | 5:2682b8d7e871 | 47 | SPI_STMPE610 TSC(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TSC) ; |
neilt6 | 0:407dafce805d | 48 | |
neilt6 | 0:407dafce805d | 49 | int main() |
neilt6 | 0:407dafce805d | 50 | { |
neilt6 | 0:407dafce805d | 51 | //Configure the display driver |
neilt6 | 0:407dafce805d | 52 | TFT.background(Black); |
neilt6 | 0:407dafce805d | 53 | TFT.foreground(White); |
neilt6 | 0:407dafce805d | 54 | TFT.cls(); |
neilt6 | 0:407dafce805d | 55 | |
neilt6 | 0:407dafce805d | 56 | //Print a welcome message |
neilt6 | 0:407dafce805d | 57 | TFT.set_font((unsigned char*) Arial12x12); |
neilt6 | 0:407dafce805d | 58 | TFT.locate(0,0); |
neilt6 | 0:407dafce805d | 59 | TFT.printf("Hello Mbed"); |
neilt6 | 0:407dafce805d | 60 | |
neilt6 | 0:407dafce805d | 61 | //Wait for 5 seconds |
neilt6 | 0:407dafce805d | 62 | wait(5.0); |
neilt6 | 0:407dafce805d | 63 | |
neilt6 | 0:407dafce805d | 64 | //Draw some graphics |
neilt6 | 0:407dafce805d | 65 | TFT.cls(); |
neilt6 | 0:407dafce805d | 66 | TFT.set_font((unsigned char*) Arial24x23); |
neilt6 | 0:407dafce805d | 67 | TFT.locate(100,100); |
neilt6 | 0:407dafce805d | 68 | TFT.printf("Graphic"); |
neilt6 | 0:407dafce805d | 69 | |
neilt6 | 0:407dafce805d | 70 | TFT.line(0,0,100,0,Green); |
neilt6 | 0:407dafce805d | 71 | TFT.line(0,0,0,200,Green); |
neilt6 | 0:407dafce805d | 72 | TFT.line(0,0,100,200,Green); |
neilt6 | 0:407dafce805d | 73 | |
neilt6 | 0:407dafce805d | 74 | TFT.rect(100,50,150,100,Red); |
neilt6 | 0:407dafce805d | 75 | TFT.fillrect(180,25,220,70,Blue); |
neilt6 | 0:407dafce805d | 76 | |
neilt6 | 0:407dafce805d | 77 | TFT.circle(80,150,33,White); |
neilt6 | 0:407dafce805d | 78 | TFT.fillcircle(160,190,20,Yellow); |
neilt6 | 0:407dafce805d | 79 | |
neilt6 | 0:407dafce805d | 80 | double s; |
neilt6 | 0:407dafce805d | 81 | for (int i = 0; i < 320; i++) { |
neilt6 | 0:407dafce805d | 82 | s = 20 * sin((long double)i / 10); |
neilt6 | 0:407dafce805d | 83 | TFT.pixel(i, 100 + (int)s, Red); |
neilt6 | 0:407dafce805d | 84 | } |
neilt6 | 0:407dafce805d | 85 | |
neilt6 | 0:407dafce805d | 86 | //Wait for 5 seconds |
neilt6 | 0:407dafce805d | 87 | wait(5.0); |
neilt6 | 0:407dafce805d | 88 | |
neilt6 | 0:407dafce805d | 89 | //Multiple fonts |
neilt6 | 0:407dafce805d | 90 | TFT.foreground(White); |
neilt6 | 0:407dafce805d | 91 | TFT.background(Blue); |
neilt6 | 0:407dafce805d | 92 | TFT.cls(); |
neilt6 | 0:407dafce805d | 93 | TFT.set_font((unsigned char*) Arial24x23); |
neilt6 | 0:407dafce805d | 94 | TFT.locate(0,0); |
screamer | 2:5c2f6ff36ff1 | 95 | TFT.printf("Different Fonts:"); |
neilt6 | 0:407dafce805d | 96 | TFT.set_font((unsigned char*) Neu42x35); |
neilt6 | 0:407dafce805d | 97 | TFT.locate(0,30); |
hcseran | 5:2682b8d7e871 | 98 | TFT.printf("Hello Henry"); |
neilt6 | 0:407dafce805d | 99 | TFT.set_font((unsigned char*) Arial24x23); |
neilt6 | 0:407dafce805d | 100 | TFT.locate(20,80); |
hcseran | 5:2682b8d7e871 | 101 | TFT.printf("Hello Henry"); |
neilt6 | 0:407dafce805d | 102 | TFT.set_font((unsigned char*) Arial12x12); |
neilt6 | 0:407dafce805d | 103 | TFT.locate(35,120); |
hcseran | 5:2682b8d7e871 | 104 | TFT.printf("Hello Henry"); |
hcseran | 5:2682b8d7e871 | 105 | wait(3.0); |
hcseran | 5:2682b8d7e871 | 106 | |
hcseran | 5:2682b8d7e871 | 107 | uint16_t touched, x, y, z ; |
hcseran | 5:2682b8d7e871 | 108 | TFT.printf("Test SPI STMPE610\n\r") ; |
hcseran | 5:2682b8d7e871 | 109 | while (true) { |
hcseran | 5:2682b8d7e871 | 110 | touched = TSC.getRAWPoint(&x, &y, &z) ; |
hcseran | 5:2682b8d7e871 | 111 | if (touched) { |
hcseran | 5:2682b8d7e871 | 112 | TFT.cls(); |
hcseran | 5:2682b8d7e871 | 113 | TFT.locate(0,150); |
hcseran | 5:2682b8d7e871 | 114 | TFT.printf("x = %d\n\r y = %d\n\r z = %d\n\r", x, y, z) ; |
hcseran | 5:2682b8d7e871 | 115 | } |
hcseran | 5:2682b8d7e871 | 116 | wait(0.1) ; |
hcseran | 5:2682b8d7e871 | 117 | } |
neilt6 | 0:407dafce805d | 118 | } |