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

main.cpp

Committer:
hcseran
Date:
2015-04-03
Revision:
5:2682b8d7e871
Parent:
2:5c2f6ff36ff1

File content as of revision 5:2682b8d7e871:

/*
  main.cpp
  2014 Copyright (c) Seeed Technology Inc.  All right reserved.

  Author:lawliet zou(lawliet.zou@gmail.com)
  2014-02-17

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include "mbed.h"
#include "SeeedStudioTFTv2.h"
#include "Arial12x12.h"
#include "Arial24x23.h"
#include "Arial28x28.h"
#include "font_big.h"
#include "SPI_STMPE610.h"

#define PIN_XP          A3
#define PIN_XM          A1
#define PIN_YP          A2
#define PIN_YM          A0
#define PIN_MOSI        D11
#define PIN_MISO        D12
#define PIN_SCLK        D13
//#define PIN_CS_TFT      D5    // for SEED
#define PIN_CS_TFT      D10    // for adafruit
//#define PIN_DC_TFT      D6      // for SEED
#define PIN_DC_TFT      D9      // for adafruit
#define PIN_BL_TFT      D7
#define PIN_CS_SD       D4
#define PIN_CS_TSC      D8

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);
SPI_STMPE610 TSC(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TSC) ;

int main()
{
    //Configure the display driver
    TFT.background(Black);
    TFT.foreground(White);
    TFT.cls();

    //Print a welcome message
    TFT.set_font((unsigned char*) Arial12x12);
    TFT.locate(0,0);
    TFT.printf("Hello Mbed");

    //Wait for 5 seconds
    wait(5.0);

    //Draw some graphics
    TFT.cls();
    TFT.set_font((unsigned char*) Arial24x23);
    TFT.locate(100,100);
    TFT.printf("Graphic");

    TFT.line(0,0,100,0,Green);
    TFT.line(0,0,0,200,Green);
    TFT.line(0,0,100,200,Green);

    TFT.rect(100,50,150,100,Red);
    TFT.fillrect(180,25,220,70,Blue);

    TFT.circle(80,150,33,White);
    TFT.fillcircle(160,190,20,Yellow);

    double s;
    for (int i = 0; i < 320; i++) {
        s = 20 * sin((long double)i / 10);
        TFT.pixel(i, 100 + (int)s, Red);
    }

    //Wait for 5 seconds
    wait(5.0);

    //Multiple fonts
    TFT.foreground(White);
    TFT.background(Blue);
    TFT.cls();
    TFT.set_font((unsigned char*) Arial24x23);
    TFT.locate(0,0);
    TFT.printf("Different Fonts:");
    TFT.set_font((unsigned char*) Neu42x35);
    TFT.locate(0,30);
    TFT.printf("Hello Henry");
    TFT.set_font((unsigned char*) Arial24x23);
    TFT.locate(20,80);
    TFT.printf("Hello Henry");
    TFT.set_font((unsigned char*) Arial12x12);
    TFT.locate(35,120);
    TFT.printf("Hello Henry");
    wait(3.0);
    
    uint16_t touched, x, y, z ;
    TFT.printf("Test SPI STMPE610\n\r") ;
    while (true) {
       touched = TSC.getRAWPoint(&x, &y, &z) ;
       if (touched) {
           TFT.cls();
           TFT.locate(0,150);
           TFT.printf("x = %d\n\r y = %d\n\r z = %d\n\r", x, y, z) ;
       }
       wait(0.1) ;
   }
}