Lab4

Dependencies:   SeeedStudioTFTv2 TFT_fonts mbed

Fork of Seeed_TFT_Touch_Shield by Shields

Committer:
uswickra
Date:
Fri Sep 26 12:40:19 2014 +0000
Revision:
4:ebcf8d366b91
Parent:
2:5c2f6ff36ff1
Child:
6:ebffa73d4f95
Lab 4;

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"
uswickra 4:ebcf8d366b91 29 #include "Panel.h"
uswickra 4:ebcf8d366b91 30 #include "Button.h"
neilt6 0:407dafce805d 31
screamer 2:5c2f6ff36ff1 32 #define PIN_XP A3
screamer 2:5c2f6ff36ff1 33 #define PIN_XM A1
screamer 2:5c2f6ff36ff1 34 #define PIN_YP A2
screamer 2:5c2f6ff36ff1 35 #define PIN_YM A0
screamer 2:5c2f6ff36ff1 36 #define PIN_MOSI D11
screamer 2:5c2f6ff36ff1 37 #define PIN_MISO D12
screamer 2:5c2f6ff36ff1 38 #define PIN_SCLK D13
screamer 2:5c2f6ff36ff1 39 #define PIN_CS_TFT D5
screamer 2:5c2f6ff36ff1 40 #define PIN_DC_TFT D6
screamer 2:5c2f6ff36ff1 41 #define PIN_BL_TFT D7
screamer 2:5c2f6ff36ff1 42 #define PIN_CS_SD D4
lawliet 1:b2794eb7c940 43
screamer 2:5c2f6ff36ff1 44 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);
uswickra 4:ebcf8d366b91 45 Serial pc(USBTX, USBRX);
neilt6 0:407dafce805d 46
neilt6 0:407dafce805d 47 int main()
neilt6 0:407dafce805d 48 {
neilt6 0:407dafce805d 49 //Configure the display driver
uswickra 4:ebcf8d366b91 50 // TFT.background(Black);
uswickra 4:ebcf8d366b91 51 // TFT.foreground(White);
uswickra 4:ebcf8d366b91 52 // TFT.cls();
uswickra 4:ebcf8d366b91 53 //
uswickra 4:ebcf8d366b91 54 // //Print a welcome message
uswickra 4:ebcf8d366b91 55 // TFT.set_font((unsigned char*) Arial12x12);
uswickra 4:ebcf8d366b91 56 // TFT.locate(0,0);
uswickra 4:ebcf8d366b91 57 // TFT.printf("Hello Mbed");
uswickra 4:ebcf8d366b91 58 //
uswickra 4:ebcf8d366b91 59 // //Wait for 5 seconds
uswickra 4:ebcf8d366b91 60 // wait(5.0);
uswickra 4:ebcf8d366b91 61 //
uswickra 4:ebcf8d366b91 62 // //Draw some graphics
uswickra 4:ebcf8d366b91 63 // TFT.cls();
uswickra 4:ebcf8d366b91 64 // TFT.set_font((unsigned char*) Arial24x23);
uswickra 4:ebcf8d366b91 65 // TFT.locate(100,100);
uswickra 4:ebcf8d366b91 66 // TFT.printf("Graphic");
uswickra 4:ebcf8d366b91 67 //
uswickra 4:ebcf8d366b91 68 // TFT.line(0,0,100,0,Green);
uswickra 4:ebcf8d366b91 69 // TFT.line(0,0,0,200,Green);
uswickra 4:ebcf8d366b91 70 // TFT.line(0,0,100,200,Green);
uswickra 4:ebcf8d366b91 71 //
uswickra 4:ebcf8d366b91 72 // TFT.rect(100,50,150,100,Red);
uswickra 4:ebcf8d366b91 73 // TFT.fillrect(180,25,220,70,Blue);
uswickra 4:ebcf8d366b91 74 //
uswickra 4:ebcf8d366b91 75 // TFT.circle(80,150,33,White);
uswickra 4:ebcf8d366b91 76 // TFT.fillcircle(160,190,20,Yellow);
uswickra 4:ebcf8d366b91 77 //
uswickra 4:ebcf8d366b91 78 // double s;
uswickra 4:ebcf8d366b91 79 // for (int i = 0; i < 320; i++) {
uswickra 4:ebcf8d366b91 80 // s = 20 * sin((long double)i / 10);
uswickra 4:ebcf8d366b91 81 // TFT.pixel(i, 100 + (int)s, Red);
uswickra 4:ebcf8d366b91 82 // }
uswickra 4:ebcf8d366b91 83 //
uswickra 4:ebcf8d366b91 84 // //Wait for 5 seconds
uswickra 4:ebcf8d366b91 85 //// wait(5.0);
uswickra 4:ebcf8d366b91 86 //
uswickra 4:ebcf8d366b91 87 // //Multiple fonts
uswickra 4:ebcf8d366b91 88 // //TFT.foreground(White);
uswickra 4:ebcf8d366b91 89 //// TFT.background(Blue);
uswickra 4:ebcf8d366b91 90 //// TFT.cls();
uswickra 4:ebcf8d366b91 91 //// TFT.set_font((unsigned char*) Arial24x23);
uswickra 4:ebcf8d366b91 92 //// TFT.locate(0,0);
uswickra 4:ebcf8d366b91 93 //// TFT.printf("Different Fonts:");
uswickra 4:ebcf8d366b91 94 //// TFT.set_font((unsigned char*) Neu42x35);
uswickra 4:ebcf8d366b91 95 //// TFT.locate(0,30);
uswickra 4:ebcf8d366b91 96 //// TFT.printf("Hello Mbed 1");
uswickra 4:ebcf8d366b91 97 //// TFT.set_font((unsigned char*) Arial24x23);
uswickra 4:ebcf8d366b91 98 //// TFT.locate(20,80);
uswickra 4:ebcf8d366b91 99 //// TFT.printf("Hello Mbed 2");
uswickra 4:ebcf8d366b91 100 //// TFT.set_font((unsigned char*) Arial12x12);
uswickra 4:ebcf8d366b91 101 //// TFT.locate(35,120);
uswickra 4:ebcf8d366b91 102 //
uswickra 4:ebcf8d366b91 103 // //Wait for 5 seconds
uswickra 4:ebcf8d366b91 104 // wait(1.0);
uswickra 4:ebcf8d366b91 105
uswickra 4:ebcf8d366b91 106 //Configure the display driver
neilt6 0:407dafce805d 107 TFT.background(Black);
neilt6 0:407dafce805d 108 TFT.foreground(White);
neilt6 0:407dafce805d 109 TFT.cls();
uswickra 4:ebcf8d366b91 110 // TFT.set_font((unsigned char*) Arial24x23);
uswickra 4:ebcf8d366b91 111 // TFT.locate(0,0);
uswickra 4:ebcf8d366b91 112 // TFT.printf("Calibrating...");
neilt6 0:407dafce805d 113
uswickra 4:ebcf8d366b91 114 wait(1.0);
uswickra 4:ebcf8d366b91 115
uswickra 4:ebcf8d366b91 116 pc.printf("START..... \r\n");
uswickra 4:ebcf8d366b91 117
uswickra 4:ebcf8d366b91 118 Panel window(0, 0, 240, 320, Navy, Black, 3, 1);
uswickra 4:ebcf8d366b91 119 Panel textDisplay(White, Black, 1, 1, 2, 2);
uswickra 4:ebcf8d366b91 120
uswickra 4:ebcf8d366b91 121 //create Key Panel
uswickra 4:ebcf8d366b91 122 //Panel( back_color, border_color, w, h, rows, cols);
uswickra 4:ebcf8d366b91 123 Panel keyPanel(Black, Black, 1, 2, 5, 10);
uswickra 4:ebcf8d366b91 124
uswickra 4:ebcf8d366b91 125 //create first row keys
uswickra 4:ebcf8d366b91 126 Button Key_Q("W",DarkGrey,White);
uswickra 4:ebcf8d366b91 127 Button Key_W("Q",DarkGrey,White);
uswickra 4:ebcf8d366b91 128 Button Key_E("E",DarkGrey,White);
uswickra 4:ebcf8d366b91 129 Button Key_R("R",DarkGrey,White);
uswickra 4:ebcf8d366b91 130 Button Key_T("T",DarkGrey,White);
uswickra 4:ebcf8d366b91 131 Button Key_Y("Y",DarkGrey,White);
uswickra 4:ebcf8d366b91 132 Button Key_U("U",DarkGrey,White);
uswickra 4:ebcf8d366b91 133 Button Key_I("I",DarkGrey,White);
uswickra 4:ebcf8d366b91 134 Button Key_O("O",DarkGrey,White);
uswickra 4:ebcf8d366b91 135 Button Key_P("P",DarkGrey,White);
uswickra 4:ebcf8d366b91 136
uswickra 4:ebcf8d366b91 137 //second row keys
uswickra 4:ebcf8d366b91 138 Button Key_A("A",DarkGrey,White);
uswickra 4:ebcf8d366b91 139 Button Key_S("S",DarkGrey,White);
uswickra 4:ebcf8d366b91 140 Button Key_D("D",DarkGrey,White);
uswickra 4:ebcf8d366b91 141 Button Key_F("F",DarkGrey,White);
uswickra 4:ebcf8d366b91 142 Button Key_G("G",DarkGrey,White);
uswickra 4:ebcf8d366b91 143 Button Key_H("H",DarkGrey,White);
uswickra 4:ebcf8d366b91 144 Button Key_J("J",DarkGrey,White);
uswickra 4:ebcf8d366b91 145 Button Key_K("K",DarkGrey,White);
uswickra 4:ebcf8d366b91 146 Button Key_L("L",DarkGrey,White);
uswickra 4:ebcf8d366b91 147 Button Key_COMMA(",",DarkGrey,White);
uswickra 4:ebcf8d366b91 148
uswickra 4:ebcf8d366b91 149 //third row keys
uswickra 4:ebcf8d366b91 150 Button Key_SHIFT("s^",DarkGrey,White);
uswickra 4:ebcf8d366b91 151 Button Key_Z("Z",DarkGrey,White);
uswickra 4:ebcf8d366b91 152 Button Key_X("X",DarkGrey,White);
uswickra 4:ebcf8d366b91 153 Button Key_C("C",DarkGrey,White);
uswickra 4:ebcf8d366b91 154 Button Key_V("V",DarkGrey,White);
uswickra 4:ebcf8d366b91 155 Button Key_B("B",DarkGrey,White);
uswickra 4:ebcf8d366b91 156 Button Key_N("N",DarkGrey,White);
uswickra 4:ebcf8d366b91 157 Button Key_M("M",DarkGrey,White);
uswickra 4:ebcf8d366b91 158 Button Key_BKSPACE("<-",DarkGrey,White);
uswickra 4:ebcf8d366b91 159 Button Key_DOT(".",DarkGrey,White);
uswickra 4:ebcf8d366b91 160
uswickra 4:ebcf8d366b91 161 //fourth row keys
uswickra 4:ebcf8d366b91 162 Button Key_SEND("SEND",DarkGrey,White,3,1);
uswickra 4:ebcf8d366b91 163 Button Key_SPACE(" SPACE",DarkGrey,White,4,1);
uswickra 4:ebcf8d366b91 164 Button Key_NEWLINE("n^",DarkGrey,White,1,1);
uswickra 4:ebcf8d366b91 165 Button Key_CALL_MENU("CALL",DarkGrey,White,2,1);
uswickra 4:ebcf8d366b91 166
uswickra 4:ebcf8d366b91 167 window.addWidget(&textDisplay);
uswickra 4:ebcf8d366b91 168 window.addWidget(&keyPanel);
uswickra 4:ebcf8d366b91 169
uswickra 4:ebcf8d366b91 170 keyPanel.addWidget(&Key_Q);
uswickra 4:ebcf8d366b91 171 keyPanel.addWidget(&Key_W);
uswickra 4:ebcf8d366b91 172 keyPanel.addWidget(&Key_E);
uswickra 4:ebcf8d366b91 173 keyPanel.addWidget(&Key_R);
uswickra 4:ebcf8d366b91 174 keyPanel.addWidget(&Key_T);
uswickra 4:ebcf8d366b91 175 keyPanel.addWidget(&Key_Y);
uswickra 4:ebcf8d366b91 176 keyPanel.addWidget(&Key_U);
uswickra 4:ebcf8d366b91 177 keyPanel.addWidget(&Key_I);
uswickra 4:ebcf8d366b91 178 keyPanel.addWidget(&Key_O);
uswickra 4:ebcf8d366b91 179 keyPanel.addWidget(&Key_P);
uswickra 4:ebcf8d366b91 180 //
uswickra 4:ebcf8d366b91 181 keyPanel.addWidget(&Key_A);
uswickra 4:ebcf8d366b91 182 keyPanel.addWidget(&Key_S);
uswickra 4:ebcf8d366b91 183 keyPanel.addWidget(&Key_D);
uswickra 4:ebcf8d366b91 184 keyPanel.addWidget(&Key_F);
uswickra 4:ebcf8d366b91 185 keyPanel.addWidget(&Key_G);
uswickra 4:ebcf8d366b91 186 keyPanel.addWidget(&Key_H);
uswickra 4:ebcf8d366b91 187 keyPanel.addWidget(&Key_J);
uswickra 4:ebcf8d366b91 188 keyPanel.addWidget(&Key_K);
uswickra 4:ebcf8d366b91 189 keyPanel.addWidget(&Key_L);
uswickra 4:ebcf8d366b91 190 keyPanel.addWidget(&Key_COMMA);
uswickra 4:ebcf8d366b91 191 //
uswickra 4:ebcf8d366b91 192 keyPanel.addWidget(&Key_SHIFT);
uswickra 4:ebcf8d366b91 193 keyPanel.addWidget(&Key_Z);
uswickra 4:ebcf8d366b91 194 keyPanel.addWidget(&Key_X);
uswickra 4:ebcf8d366b91 195 keyPanel.addWidget(&Key_C);
uswickra 4:ebcf8d366b91 196 keyPanel.addWidget(&Key_V);
uswickra 4:ebcf8d366b91 197 keyPanel.addWidget(&Key_B);
uswickra 4:ebcf8d366b91 198 keyPanel.addWidget(&Key_N);
uswickra 4:ebcf8d366b91 199 keyPanel.addWidget(&Key_M);
uswickra 4:ebcf8d366b91 200 keyPanel.addWidget(&Key_BKSPACE);
uswickra 4:ebcf8d366b91 201 keyPanel.addWidget(&Key_DOT);
uswickra 4:ebcf8d366b91 202 //
uswickra 4:ebcf8d366b91 203 keyPanel.addWidget(&Key_SEND);
uswickra 4:ebcf8d366b91 204 keyPanel.addWidget(&Key_SPACE);
uswickra 4:ebcf8d366b91 205 keyPanel.addWidget(&Key_NEWLINE);
uswickra 4:ebcf8d366b91 206 keyPanel.addWidget(&Key_CALL_MENU);
uswickra 4:ebcf8d366b91 207
uswickra 4:ebcf8d366b91 208 //DIAL Pad
uswickra 4:ebcf8d366b91 209 Panel dialPanel(Black, Black, 1, 2, 4, 3);
uswickra 4:ebcf8d366b91 210 Button Key_1("1",DarkGrey,White);
uswickra 4:ebcf8d366b91 211 Button Key_2("2",DarkGrey,White);
uswickra 4:ebcf8d366b91 212 Button Key_3("3",DarkGrey,White);
uswickra 4:ebcf8d366b91 213
uswickra 4:ebcf8d366b91 214 Button Key_4("4",DarkGrey,White);
uswickra 4:ebcf8d366b91 215 Button Key_5("5",DarkGrey,White);
uswickra 4:ebcf8d366b91 216 Button Key_6("6",DarkGrey,White);
uswickra 4:ebcf8d366b91 217
uswickra 4:ebcf8d366b91 218 Button Key_7("7",DarkGrey,White);
uswickra 4:ebcf8d366b91 219 Button Key_8("8",DarkGrey,White);
uswickra 4:ebcf8d366b91 220 Button Key_9("9",DarkGrey,White);
uswickra 4:ebcf8d366b91 221
uswickra 4:ebcf8d366b91 222 Button Key_CALL("CALL",DarkGrey,White);
uswickra 4:ebcf8d366b91 223 Button Key_0("0",DarkGrey,White);
uswickra 4:ebcf8d366b91 224 Button Key_SMS("SMS",DarkGrey,White);
uswickra 4:ebcf8d366b91 225
uswickra 4:ebcf8d366b91 226 dialPanel.addWidget(&Key_1);
uswickra 4:ebcf8d366b91 227 dialPanel.addWidget(&Key_2);
uswickra 4:ebcf8d366b91 228 dialPanel.addWidget(&Key_3);
uswickra 4:ebcf8d366b91 229 dialPanel.addWidget(&Key_4);
uswickra 4:ebcf8d366b91 230 dialPanel.addWidget(&Key_5);
uswickra 4:ebcf8d366b91 231 dialPanel.addWidget(&Key_6);
uswickra 4:ebcf8d366b91 232 dialPanel.addWidget(&Key_7);
uswickra 4:ebcf8d366b91 233 dialPanel.addWidget(&Key_8);
uswickra 4:ebcf8d366b91 234 dialPanel.addWidget(&Key_9);
uswickra 4:ebcf8d366b91 235 dialPanel.addWidget(&Key_CALL);
uswickra 4:ebcf8d366b91 236 dialPanel.addWidget(&Key_0);
uswickra 4:ebcf8d366b91 237 dialPanel.addWidget(&Key_SMS);
uswickra 4:ebcf8d366b91 238
uswickra 4:ebcf8d366b91 239 pc.printf("LOOP..... \r\n");
uswickra 4:ebcf8d366b91 240 wait(2);
uswickra 4:ebcf8d366b91 241
uswickra 4:ebcf8d366b91 242 // TFT.calibrate();
uswickra 4:ebcf8d366b91 243 point p ;
uswickra 4:ebcf8d366b91 244 while(true) {
uswickra 4:ebcf8d366b91 245
uswickra 4:ebcf8d366b91 246 TFT.getPixel(p);
uswickra 4:ebcf8d366b91 247 window.redraw();
uswickra 4:ebcf8d366b91 248
uswickra 4:ebcf8d366b91 249 window.remove_child();
uswickra 4:ebcf8d366b91 250 window.addWidget(&dialPanel);
uswickra 4:ebcf8d366b91 251 window.refresh();
uswickra 4:ebcf8d366b91 252 window.redraw();
uswickra 4:ebcf8d366b91 253
uswickra 4:ebcf8d366b91 254 wait(2);
uswickra 4:ebcf8d366b91 255
uswickra 4:ebcf8d366b91 256 window.remove_child();
uswickra 4:ebcf8d366b91 257 window.addWidget(&keyPanel);
uswickra 4:ebcf8d366b91 258 window.refresh();
uswickra 4:ebcf8d366b91 259 window.redraw();
uswickra 4:ebcf8d366b91 260 wait(2);
uswickra 4:ebcf8d366b91 261
neilt6 0:407dafce805d 262
neilt6 0:407dafce805d 263 }
neilt6 0:407dafce805d 264
neilt6 0:407dafce805d 265 }