Setup for Adafruit 2.8" TFT with touch screen and SD card

Dependencies:   SeeedStudioTFTv2 TFT_fonts mbed

Fork of Seeed_TFT_Touch_Shield by Shields

Committer:
robouden
Date:
Fri Jun 06 02:45:08 2014 +0000
Revision:
3:00e7be78fe14
Parent:
2:5c2f6ff36ff1
Setup for Adafruit 2.8 " TFT touch screen

Who changed what in which revision?

UserRevisionLine numberNew 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"
neilt6 0:407dafce805d 29
screamer 2:5c2f6ff36ff1 30 #define PIN_XP A3
screamer 2:5c2f6ff36ff1 31 #define PIN_XM A1
screamer 2:5c2f6ff36ff1 32 #define PIN_YP A2
screamer 2:5c2f6ff36ff1 33 #define PIN_YM A0
screamer 2:5c2f6ff36ff1 34 #define PIN_MOSI D11
screamer 2:5c2f6ff36ff1 35 #define PIN_MISO D12
screamer 2:5c2f6ff36ff1 36 #define PIN_SCLK D13
robouden 3:00e7be78fe14 37 #define PIN_CS_TFT D10
robouden 3:00e7be78fe14 38 #define PIN_DC_TFT D9
screamer 2:5c2f6ff36ff1 39 #define PIN_BL_TFT D7
screamer 2:5c2f6ff36ff1 40 #define PIN_CS_SD D4
lawliet 1:b2794eb7c940 41
screamer 2:5c2f6ff36ff1 42 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);
neilt6 0:407dafce805d 43
neilt6 0:407dafce805d 44 int main()
neilt6 0:407dafce805d 45 {
neilt6 0:407dafce805d 46 //Configure the display driver
neilt6 0:407dafce805d 47 TFT.background(Black);
neilt6 0:407dafce805d 48 TFT.foreground(White);
neilt6 0:407dafce805d 49 TFT.cls();
neilt6 0:407dafce805d 50
neilt6 0:407dafce805d 51 //Print a welcome message
neilt6 0:407dafce805d 52 TFT.set_font((unsigned char*) Arial12x12);
neilt6 0:407dafce805d 53 TFT.locate(0,0);
neilt6 0:407dafce805d 54 TFT.printf("Hello Mbed");
neilt6 0:407dafce805d 55
neilt6 0:407dafce805d 56 //Wait for 5 seconds
neilt6 0:407dafce805d 57 wait(5.0);
neilt6 0:407dafce805d 58
neilt6 0:407dafce805d 59 //Draw some graphics
neilt6 0:407dafce805d 60 TFT.cls();
neilt6 0:407dafce805d 61 TFT.set_font((unsigned char*) Arial24x23);
neilt6 0:407dafce805d 62 TFT.locate(100,100);
neilt6 0:407dafce805d 63 TFT.printf("Graphic");
neilt6 0:407dafce805d 64
neilt6 0:407dafce805d 65 TFT.line(0,0,100,0,Green);
neilt6 0:407dafce805d 66 TFT.line(0,0,0,200,Green);
neilt6 0:407dafce805d 67 TFT.line(0,0,100,200,Green);
neilt6 0:407dafce805d 68
neilt6 0:407dafce805d 69 TFT.rect(100,50,150,100,Red);
neilt6 0:407dafce805d 70 TFT.fillrect(180,25,220,70,Blue);
neilt6 0:407dafce805d 71
neilt6 0:407dafce805d 72 TFT.circle(80,150,33,White);
neilt6 0:407dafce805d 73 TFT.fillcircle(160,190,20,Yellow);
neilt6 0:407dafce805d 74
neilt6 0:407dafce805d 75 double s;
neilt6 0:407dafce805d 76 for (int i = 0; i < 320; i++) {
neilt6 0:407dafce805d 77 s = 20 * sin((long double)i / 10);
neilt6 0:407dafce805d 78 TFT.pixel(i, 100 + (int)s, Red);
neilt6 0:407dafce805d 79 }
neilt6 0:407dafce805d 80
neilt6 0:407dafce805d 81 //Wait for 5 seconds
neilt6 0:407dafce805d 82 wait(5.0);
neilt6 0:407dafce805d 83
neilt6 0:407dafce805d 84 //Multiple fonts
neilt6 0:407dafce805d 85 TFT.foreground(White);
neilt6 0:407dafce805d 86 TFT.background(Blue);
neilt6 0:407dafce805d 87 TFT.cls();
neilt6 0:407dafce805d 88 TFT.set_font((unsigned char*) Arial24x23);
neilt6 0:407dafce805d 89 TFT.locate(0,0);
screamer 2:5c2f6ff36ff1 90 TFT.printf("Different Fonts:");
neilt6 0:407dafce805d 91 TFT.set_font((unsigned char*) Neu42x35);
neilt6 0:407dafce805d 92 TFT.locate(0,30);
neilt6 0:407dafce805d 93 TFT.printf("Hello Mbed 1");
neilt6 0:407dafce805d 94 TFT.set_font((unsigned char*) Arial24x23);
neilt6 0:407dafce805d 95 TFT.locate(20,80);
neilt6 0:407dafce805d 96 TFT.printf("Hello Mbed 2");
neilt6 0:407dafce805d 97 TFT.set_font((unsigned char*) Arial12x12);
neilt6 0:407dafce805d 98 TFT.locate(35,120);
neilt6 0:407dafce805d 99 TFT.printf("Hello Mbed 3");
neilt6 0:407dafce805d 100 }