P542-Labs / Mbed 2 deprecated Lab4

Dependencies:   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 "Panel.h"
00030 #include "Button.h"
00031 
00032 #define PIN_XP          A3
00033 #define PIN_XM          A1
00034 #define PIN_YP          A2
00035 #define PIN_YM          A0
00036 #define PIN_MOSI        D11
00037 #define PIN_MISO        D12
00038 #define PIN_SCLK        D13
00039 #define PIN_CS_TFT      D5
00040 #define PIN_DC_TFT      D6
00041 #define PIN_BL_TFT      D7
00042 #define PIN_CS_SD       D4
00043 
00044 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);
00045 Serial pc(USBTX, USBRX);
00046 
00047 int main()
00048 {
00049     //Configure the display driver
00050 //    TFT.background(Black);
00051 //    TFT.foreground(White);
00052 //    TFT.cls();
00053 //
00054 //    //Print a welcome message
00055 //    TFT.set_font((unsigned char*) Arial12x12);
00056 //    TFT.locate(0,0);
00057 //    TFT.printf("Hello Mbed");
00058 //
00059 //    //Wait for 5 seconds
00060 //    wait(5.0);
00061 //
00062 //    //Draw some graphics
00063 //    TFT.cls();
00064 //    TFT.set_font((unsigned char*) Arial24x23);
00065 //    TFT.locate(100,100);
00066 //    TFT.printf("Graphic");
00067 //
00068 //    TFT.line(0,0,100,0,Green);
00069 //    TFT.line(0,0,0,200,Green);
00070 //    TFT.line(0,0,100,200,Green);
00071 //
00072 //    TFT.rect(100,50,150,100,Red);
00073 //    TFT.fillrect(180,25,220,70,Blue);
00074 //
00075 //    TFT.circle(80,150,33,White);
00076 //    TFT.fillcircle(160,190,20,Yellow);
00077 //
00078 //    double s;
00079 //    for (int i = 0; i < 320; i++) {
00080 //        s = 20 * sin((long double)i / 10);
00081 //        TFT.pixel(i, 100 + (int)s, Red);
00082 //    }
00083 //
00084 //    //Wait for 5 seconds
00085 ////    wait(5.0);
00086 //
00087 //    //Multiple fonts
00088 //    //TFT.foreground(White);
00089 ////    TFT.background(Blue);
00090 ////    TFT.cls();
00091 ////    TFT.set_font((unsigned char*) Arial24x23);
00092 ////    TFT.locate(0,0);
00093 ////    TFT.printf("Different Fonts:");
00094 ////    TFT.set_font((unsigned char*) Neu42x35);
00095 ////    TFT.locate(0,30);
00096 ////    TFT.printf("Hello Mbed 1");
00097 ////    TFT.set_font((unsigned char*) Arial24x23);
00098 ////    TFT.locate(20,80);
00099 ////    TFT.printf("Hello Mbed 2");
00100 ////    TFT.set_font((unsigned char*) Arial12x12);
00101 ////    TFT.locate(35,120);
00102 //
00103 //    //Wait for 5 seconds
00104 //    wait(1.0);
00105 
00106     //Configure the display driver
00107     TFT.background(Black);
00108     TFT.foreground(White);
00109     TFT.cls();
00110 //    TFT.set_font((unsigned char*) Arial24x23);
00111 //    TFT.locate(0,0);
00112 //    TFT.printf("Calibrating...");
00113 
00114     wait(1.0);
00115     
00116     pc.printf("START..... \r\n");
00117     
00118     Panel window(0, 0, 240, 320, Navy, Black, 3, 1);
00119     Panel textDisplay(White, Black, 1, 1, 2, 2);
00120     
00121     //create Key Panel
00122     //Panel( back_color,  border_color, w, h, rows, cols); 
00123     Panel keyPanel(Black, Black, 1, 2, 5, 10);
00124     
00125     //create first row keys
00126     Button Key_Q("W",DarkGrey,White);
00127     Button Key_W("Q",DarkGrey,White);
00128     Button Key_E("E",DarkGrey,White);
00129     Button Key_R("R",DarkGrey,White);
00130     Button Key_T("T",DarkGrey,White);
00131     Button Key_Y("Y",DarkGrey,White);
00132     Button Key_U("U",DarkGrey,White);
00133     Button Key_I("I",DarkGrey,White);
00134     Button Key_O("O",DarkGrey,White);
00135     Button Key_P("P",DarkGrey,White);
00136     
00137     //second row keys
00138     Button Key_A("A",DarkGrey,White);
00139     Button Key_S("S",DarkGrey,White);
00140     Button Key_D("D",DarkGrey,White);
00141     Button Key_F("F",DarkGrey,White);
00142     Button Key_G("G",DarkGrey,White);
00143     Button Key_H("H",DarkGrey,White);
00144     Button Key_J("J",DarkGrey,White);
00145     Button Key_K("K",DarkGrey,White);
00146     Button Key_L("L",DarkGrey,White);
00147     Button Key_COMMA(",",DarkGrey,White);
00148     
00149      //third row keys
00150     Button Key_SHIFT("s^",DarkGrey,White);
00151     Button Key_Z("Z",DarkGrey,White);
00152     Button Key_X("X",DarkGrey,White);
00153     Button Key_C("C",DarkGrey,White);
00154     Button Key_V("V",DarkGrey,White);
00155     Button Key_B("B",DarkGrey,White);
00156     Button Key_N("N",DarkGrey,White);
00157     Button Key_M("M",DarkGrey,White);
00158     Button Key_BKSPACE("<-",DarkGrey,White);
00159     Button Key_DOT(".",DarkGrey,White);
00160     
00161     //fourth row keys
00162     Button Key_SEND("SEND",DarkGrey,White,3,1);
00163     Button Key_SPACE("  SPACE",DarkGrey,White,4,1);
00164     Button Key_NEWLINE("n^",DarkGrey,White,1,1);
00165     Button Key_CALL_MENU("CALL",DarkGrey,White,2,1);
00166     
00167     window.addWidget(&textDisplay);
00168     window.addWidget(&keyPanel);
00169     
00170     keyPanel.addWidget(&Key_Q);
00171     keyPanel.addWidget(&Key_W);
00172     keyPanel.addWidget(&Key_E);
00173     keyPanel.addWidget(&Key_R);
00174     keyPanel.addWidget(&Key_T);
00175     keyPanel.addWidget(&Key_Y);
00176     keyPanel.addWidget(&Key_U);
00177     keyPanel.addWidget(&Key_I);
00178     keyPanel.addWidget(&Key_O);
00179     keyPanel.addWidget(&Key_P);
00180     //
00181     keyPanel.addWidget(&Key_A);
00182     keyPanel.addWidget(&Key_S);
00183     keyPanel.addWidget(&Key_D);
00184     keyPanel.addWidget(&Key_F);
00185     keyPanel.addWidget(&Key_G);
00186     keyPanel.addWidget(&Key_H);
00187     keyPanel.addWidget(&Key_J);
00188     keyPanel.addWidget(&Key_K);
00189     keyPanel.addWidget(&Key_L);
00190     keyPanel.addWidget(&Key_COMMA);
00191     //
00192     keyPanel.addWidget(&Key_SHIFT);
00193     keyPanel.addWidget(&Key_Z);
00194     keyPanel.addWidget(&Key_X);
00195     keyPanel.addWidget(&Key_C);
00196     keyPanel.addWidget(&Key_V);
00197     keyPanel.addWidget(&Key_B);
00198     keyPanel.addWidget(&Key_N);
00199     keyPanel.addWidget(&Key_M);
00200     keyPanel.addWidget(&Key_BKSPACE);
00201     keyPanel.addWidget(&Key_DOT);
00202     //
00203     keyPanel.addWidget(&Key_SEND);
00204     keyPanel.addWidget(&Key_SPACE);
00205     keyPanel.addWidget(&Key_NEWLINE);
00206     keyPanel.addWidget(&Key_CALL_MENU);
00207     
00208     //DIAL Pad
00209     Panel dialPanel(Black, Black, 1, 2, 4, 3);
00210     Button Key_1("1",DarkGrey,White);
00211     Key_1.registerForEvents(&textDisplay);
00212     Button Key_2("2",DarkGrey,White);
00213     Button Key_3("3",DarkGrey,White);
00214     
00215     Button Key_4("4",DarkGrey,White);
00216     Button Key_5("5",DarkGrey,White);
00217     Button Key_6("6",DarkGrey,White);
00218     
00219     Button Key_7("7",DarkGrey,White);
00220     Button Key_8("8",DarkGrey,White);
00221     Button Key_9("9",DarkGrey,White);
00222     
00223     Button Key_CALL("CALL",DarkGrey,White);
00224     Button Key_0("0",DarkGrey,White);
00225     Button Key_SMS("SMS",DarkGrey,White);
00226     
00227     dialPanel.addWidget(&Key_1);
00228     dialPanel.addWidget(&Key_2);
00229     dialPanel.addWidget(&Key_3);
00230     dialPanel.addWidget(&Key_4);
00231     dialPanel.addWidget(&Key_5);
00232     dialPanel.addWidget(&Key_6);
00233     dialPanel.addWidget(&Key_7);
00234     dialPanel.addWidget(&Key_8);
00235     dialPanel.addWidget(&Key_9);
00236     dialPanel.addWidget(&Key_CALL);
00237     dialPanel.addWidget(&Key_0);
00238     dialPanel.addWidget(&Key_SMS);
00239     
00240     pc.printf("LOOP..... \r\n");
00241     wait(2);
00242     
00243 //    TFT.calibrate();
00244     point p ;
00245     while(true) {
00246         
00247         TFT.getPixel(p);
00248         window.redraw();
00249         
00250         window.remove_child();
00251         window.addWidget(&dialPanel);
00252         window.refresh();
00253         window.redraw();
00254         
00255         wait(2);
00256         
00257         window.remove_child();
00258         window.addWidget(&keyPanel);
00259         window.refresh();
00260         window.redraw();
00261         wait(2);
00262         
00263 
00264     }
00265 
00266 }