Lab4

Dependencies:   SeeedStudioTFTv2 TFT_fonts mbed

Fork of Seeed_TFT_Touch_Shield by Shields

Committer:
lawliet
Date:
Mon Feb 17 06:24:26 2014 +0000
Revision:
1:b2794eb7c940
Parent:
0:407dafce805d
Child:
2:5c2f6ff36ff1
Initial Version

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
lawliet 1:b2794eb7c940 30 #if defined(TARGET_LPC11U24) //SEEEDUINO_ARCH
lawliet 1:b2794eb7c940 31 #define PIN_XP P0_14
lawliet 1:b2794eb7c940 32 #define PIN_XM P0_12
lawliet 1:b2794eb7c940 33 #define PIN_YP P0_13
lawliet 1:b2794eb7c940 34 #define PIN_YM P0_11
lawliet 1:b2794eb7c940 35 #define PIN_MOSI P1_22
lawliet 1:b2794eb7c940 36 #define PIN_MISO P1_21
lawliet 1:b2794eb7c940 37 #define PIN_SCLK P1_20
lawliet 1:b2794eb7c940 38 #define PIN_CS_TFT P1_24
lawliet 1:b2794eb7c940 39 #define PIN_DC_TFT P1_25
lawliet 1:b2794eb7c940 40 #define PIN_BL_TFT P1_5
lawliet 1:b2794eb7c940 41 #define PIN_CS_SD P1_18
lawliet 1:b2794eb7c940 42 #elif defined(TARGET_LPC1768) //SEEEDUINO_ARCH_PRO
lawliet 1:b2794eb7c940 43 #define PIN_XP P0_26
lawliet 1:b2794eb7c940 44 #define PIN_XM P0_24
lawliet 1:b2794eb7c940 45 #define PIN_YP P0_25
lawliet 1:b2794eb7c940 46 #define PIN_YM P0_23
lawliet 1:b2794eb7c940 47 #define PIN_MOSI P0_18
lawliet 1:b2794eb7c940 48 #define PIN_MISO P0_17
lawliet 1:b2794eb7c940 49 #define PIN_SCLK P0_15
lawliet 1:b2794eb7c940 50 #define PIN_CS_TFT P2_3
lawliet 1:b2794eb7c940 51 #define PIN_DC_TFT P2_4
lawliet 1:b2794eb7c940 52 #define PIN_BL_TFT P2_5
lawliet 1:b2794eb7c940 53 #define PIN_CS_SD P2_2
lawliet 1:b2794eb7c940 54 #else //please redefine the following pins
lawliet 1:b2794eb7c940 55 #define PIN_XP
lawliet 1:b2794eb7c940 56 #define PIN_XM
lawliet 1:b2794eb7c940 57 #define PIN_YP
lawliet 1:b2794eb7c940 58 #define PIN_YM
lawliet 1:b2794eb7c940 59 #define PIN_MOSI
lawliet 1:b2794eb7c940 60 #define PIN_MISO
lawliet 1:b2794eb7c940 61 #define PIN_SCLK
lawliet 1:b2794eb7c940 62 #define PIN_CS_TFT
lawliet 1:b2794eb7c940 63 #define PIN_DC_TFT
lawliet 1:b2794eb7c940 64 #define PIN_BL_TFT
lawliet 1:b2794eb7c940 65 #define PIN_CS_SD
lawliet 1:b2794eb7c940 66 #endif
lawliet 1:b2794eb7c940 67
lawliet 1:b2794eb7c940 68 //SeeedStudioTFTv2 TFT(PTB3, PTB1, PTB2, PTB0, PTD2, PTD3, PTD1, PTA5, PTC8, PTC9, PTA4);
lawliet 1:b2794eb7c940 69
lawliet 1:b2794eb7c940 70 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 71
neilt6 0:407dafce805d 72 int main()
neilt6 0:407dafce805d 73 {
neilt6 0:407dafce805d 74 //Configure the display driver
neilt6 0:407dafce805d 75 TFT.background(Black);
neilt6 0:407dafce805d 76 TFT.foreground(White);
neilt6 0:407dafce805d 77 TFT.cls();
neilt6 0:407dafce805d 78
neilt6 0:407dafce805d 79 //Print a welcome message
neilt6 0:407dafce805d 80 TFT.set_font((unsigned char*) Arial12x12);
neilt6 0:407dafce805d 81 TFT.locate(0,0);
neilt6 0:407dafce805d 82 TFT.printf("Hello Mbed");
neilt6 0:407dafce805d 83
neilt6 0:407dafce805d 84 //Wait for 5 seconds
neilt6 0:407dafce805d 85 wait(5.0);
neilt6 0:407dafce805d 86
neilt6 0:407dafce805d 87 //Draw some graphics
neilt6 0:407dafce805d 88 TFT.cls();
neilt6 0:407dafce805d 89 TFT.set_font((unsigned char*) Arial24x23);
neilt6 0:407dafce805d 90 TFT.locate(100,100);
neilt6 0:407dafce805d 91 TFT.printf("Graphic");
neilt6 0:407dafce805d 92
neilt6 0:407dafce805d 93 TFT.line(0,0,100,0,Green);
neilt6 0:407dafce805d 94 TFT.line(0,0,0,200,Green);
neilt6 0:407dafce805d 95 TFT.line(0,0,100,200,Green);
neilt6 0:407dafce805d 96
neilt6 0:407dafce805d 97 TFT.rect(100,50,150,100,Red);
neilt6 0:407dafce805d 98 TFT.fillrect(180,25,220,70,Blue);
neilt6 0:407dafce805d 99
neilt6 0:407dafce805d 100 TFT.circle(80,150,33,White);
neilt6 0:407dafce805d 101 TFT.fillcircle(160,190,20,Yellow);
neilt6 0:407dafce805d 102
neilt6 0:407dafce805d 103 double s;
neilt6 0:407dafce805d 104 for (int i = 0; i < 320; i++) {
neilt6 0:407dafce805d 105 s = 20 * sin((long double)i / 10);
neilt6 0:407dafce805d 106 TFT.pixel(i, 100 + (int)s, Red);
neilt6 0:407dafce805d 107 }
neilt6 0:407dafce805d 108
neilt6 0:407dafce805d 109 //Wait for 5 seconds
neilt6 0:407dafce805d 110 wait(5.0);
neilt6 0:407dafce805d 111
neilt6 0:407dafce805d 112 //Multiple fonts
neilt6 0:407dafce805d 113 TFT.foreground(White);
neilt6 0:407dafce805d 114 TFT.background(Blue);
neilt6 0:407dafce805d 115 TFT.cls();
neilt6 0:407dafce805d 116 TFT.set_font((unsigned char*) Arial24x23);
neilt6 0:407dafce805d 117 TFT.locate(0,0);
neilt6 0:407dafce805d 118 TFT.printf("Different Fonts :");
neilt6 0:407dafce805d 119 TFT.set_font((unsigned char*) Neu42x35);
neilt6 0:407dafce805d 120 TFT.locate(0,30);
neilt6 0:407dafce805d 121 TFT.printf("Hello Mbed 1");
neilt6 0:407dafce805d 122 TFT.set_font((unsigned char*) Arial24x23);
neilt6 0:407dafce805d 123 TFT.locate(20,80);
neilt6 0:407dafce805d 124 TFT.printf("Hello Mbed 2");
neilt6 0:407dafce805d 125 TFT.set_font((unsigned char*) Arial12x12);
neilt6 0:407dafce805d 126 TFT.locate(35,120);
neilt6 0:407dafce805d 127 TFT.printf("Hello Mbed 3");
neilt6 0:407dafce805d 128 }