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 Shields

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002   main.cpp
00003   2014 Copyright (c) Seeed Technology Inc.  All right reserved.
00004 
00005   Author:lawliet zou(lawliet.zou@gmail.com)
00006   2014-02-17
00007 
00008   This library is free software; you can redistribute it and/or
00009   modify it under the terms of the GNU Lesser General Public
00010   License as published by the Free Software Foundation; either
00011   version 2.1 of the License, or (at your option) any later version.
00012 
00013   This library is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016   Lesser General Public License for more details.
00017 
00018   You should have received a copy of the GNU Lesser General Public
00019   License along with this library; if not, write to the Free Software
00020   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00021 */
00022 
00023 #include "mbed.h"
00024 #include "SeeedStudioTFTv2.h"
00025 #include "Arial12x12.h"
00026 #include "Arial24x23.h"
00027 #include "Arial28x28.h"
00028 #include "font_big.h"
00029 #include "SPI_STMPE610.h"
00030 
00031 #define PIN_XP          A3
00032 #define PIN_XM          A1
00033 #define PIN_YP          A2
00034 #define PIN_YM          A0
00035 #define PIN_MOSI        D11
00036 #define PIN_MISO        D12
00037 #define PIN_SCLK        D13
00038 //#define PIN_CS_TFT      D5    // for SEED
00039 #define PIN_CS_TFT      D10    // for adafruit
00040 //#define PIN_DC_TFT      D6      // for SEED
00041 #define PIN_DC_TFT      D9      // for adafruit
00042 #define PIN_BL_TFT      D7
00043 #define PIN_CS_SD       D4
00044 #define PIN_CS_TSC      D8
00045 
00046 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);
00047 SPI_STMPE610 TSC(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TSC) ;
00048 
00049 int main()
00050 {
00051     //Configure the display driver
00052     TFT.background(Black);
00053     TFT.foreground(White);
00054     TFT.cls();
00055 
00056     //Print a welcome message
00057     TFT.set_font((unsigned char*) Arial12x12);
00058     TFT.locate(0,0);
00059     TFT.printf("Hello Mbed");
00060 
00061     //Wait for 5 seconds
00062     wait(5.0);
00063 
00064     //Draw some graphics
00065     TFT.cls();
00066     TFT.set_font((unsigned char*) Arial24x23);
00067     TFT.locate(100,100);
00068     TFT.printf("Graphic");
00069 
00070     TFT.line(0,0,100,0,Green);
00071     TFT.line(0,0,0,200,Green);
00072     TFT.line(0,0,100,200,Green);
00073 
00074     TFT.rect(100,50,150,100,Red);
00075     TFT.fillrect(180,25,220,70,Blue);
00076 
00077     TFT.circle(80,150,33,White);
00078     TFT.fillcircle(160,190,20,Yellow);
00079 
00080     double s;
00081     for (int i = 0; i < 320; i++) {
00082         s = 20 * sin((long double)i / 10);
00083         TFT.pixel(i, 100 + (int)s, Red);
00084     }
00085 
00086     //Wait for 5 seconds
00087     wait(5.0);
00088 
00089     //Multiple fonts
00090     TFT.foreground(White);
00091     TFT.background(Blue);
00092     TFT.cls();
00093     TFT.set_font((unsigned char*) Arial24x23);
00094     TFT.locate(0,0);
00095     TFT.printf("Different Fonts:");
00096     TFT.set_font((unsigned char*) Neu42x35);
00097     TFT.locate(0,30);
00098     TFT.printf("Hello Henry");
00099     TFT.set_font((unsigned char*) Arial24x23);
00100     TFT.locate(20,80);
00101     TFT.printf("Hello Henry");
00102     TFT.set_font((unsigned char*) Arial12x12);
00103     TFT.locate(35,120);
00104     TFT.printf("Hello Henry");
00105     wait(3.0);
00106     
00107     uint16_t touched, x, y, z ;
00108     TFT.printf("Test SPI STMPE610\n\r") ;
00109     while (true) {
00110        touched = TSC.getRAWPoint(&x, &y, &z) ;
00111        if (touched) {
00112            TFT.cls();
00113            TFT.locate(0,150);
00114            TFT.printf("x = %d\n\r y = %d\n\r z = %d\n\r", x, y, z) ;
00115        }
00116        wait(0.1) ;
00117    }
00118 }