P 542 labs AI / Mbed 2 deprecated TFT_Cell_Modem

Dependencies:   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 
00030 #define PIN_XP          A3
00031 #define PIN_XM          A1
00032 #define PIN_YP          A2
00033 #define PIN_YM          A0
00034 #define PIN_MOSI        D11
00035 #define PIN_MISO        D12
00036 #define PIN_SCLK        D13
00037 #define PIN_CS_TFT      D5
00038 #define PIN_DC_TFT      D6
00039 #define PIN_BL_TFT      D7
00040 #define PIN_CS_SD       D4
00041 
00042 typedef enum { YES, MAYBE, NO } TOUCH;
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 
00046 void head() {
00047 
00048         TFT.set_font((unsigned char*) Arial12x12);
00049         //Time
00050         set_time(1387188323); // Set RTC time to 16 December 2013 10:05:23 UTC
00051         time_t seconds = time(NULL);
00052     
00053         //printf("Time as seconds since January 1, 1970 = %d\n", seconds);
00054         TFT.locate(150,0);
00055         char buffer[32];
00056         strftime(buffer, 32, "%I:%M:%S %p\n", localtime(&seconds));
00057         TFT.printf(buffer);
00058         //Print a welcome message
00059         
00060         TFT.locate(0,0);
00061         TFT.printf("Hello user");
00062     
00063 }
00064 
00065 void keypad() {
00066     
00067     TFT.cls();
00068     head();
00069     //Keypad
00070         TFT.circle(50,100,26,White);
00071         TFT.circle(50,160,26,White);
00072         TFT.circle(50,220,26,White);
00073         TFT.circle(120,100,26,White);
00074         TFT.circle(120,160,26,White);
00075         TFT.circle(120,220,26,White);
00076         TFT.circle(120,280,26,White);
00077         TFT.circle(190,100,26,White);
00078         TFT.circle(190,160,26,White);
00079         TFT.circle(190,220,26,White);
00080         TFT.circle(50,280,26,White);
00081         TFT.circle(190,280,26,White);
00082         TFT.circle(190,40,26,White);
00083         TFT.set_font((unsigned char*) Arial24x23);
00084         TFT.locate(40,84);
00085         TFT.printf("1");
00086         TFT.locate(40,144);
00087         TFT.printf("4");
00088         TFT.locate(40,204);
00089         TFT.printf("7");
00090         TFT.locate(110,84);
00091         TFT.printf("2");
00092         TFT.locate(110,144);
00093         TFT.printf("5");
00094         TFT.locate(110,204);
00095         TFT.printf("8");
00096         TFT.locate(180,84);
00097         TFT.printf("3");
00098         TFT.locate(180,144);
00099         TFT.printf("6");
00100         TFT.locate(180,204);
00101         TFT.printf("9");
00102         TFT.locate(110,264);
00103         TFT.printf("0");
00104         TFT.set_font((unsigned char*) Arial12x12);
00105         TFT.locate(110,104);
00106         TFT.printf("abc");
00107         TFT.locate(180,104);
00108         TFT.printf("def");
00109         TFT.locate(40,164);
00110         TFT.printf("ghi");
00111         TFT.locate(110,164);
00112         TFT.printf("jkl");
00113         TFT.locate(178,164);
00114         TFT.printf("mno");
00115         TFT.locate(36,224);
00116         TFT.printf("pqrs");
00117         TFT.locate(110,224);
00118         TFT.printf("tuv");
00119         TFT.locate(175,224);
00120         TFT.printf("wxyz");
00121         TFT.locate(110,284);
00122         TFT.printf("__");
00123         TFT.set_font((unsigned char*) Arial24x23);
00124         TFT.locate(40,270);
00125         TFT.printf("C");
00126         TFT.locate(180,270);
00127         TFT.printf("T");
00128         TFT.locate(180,27);
00129         TFT.printf("X");
00130         
00131       
00132 }
00133 
00134 void call() {
00135     
00136     TFT.cls();
00137         head();
00138         TFT.set_font((unsigned char*) Arial24x23);
00139         TFT.locate(50,280);
00140         TFT.printf("End Call ");
00141         TFT.line(40,270,190,270,White);
00142         TFT.line(40,310,190,310,White);
00143         TFT.line(40,270,40,310,White);
00144         TFT.line(190,270,190,310,White);
00145     
00146 }
00147 
00148 void text() {
00149     
00150     TFT.cls();
00151     head();
00152     TFT.circle(50,100,26,White);
00153         TFT.circle(50,160,26,White);
00154         TFT.circle(50,220,26,White);
00155         TFT.circle(120,100,26,White);
00156         TFT.circle(120,160,26,White);
00157         TFT.circle(120,220,26,White);
00158         TFT.circle(120,280,26,White);
00159         TFT.circle(190,100,26,White);
00160         TFT.circle(190,160,26,White);
00161         TFT.circle(190,220,26,White);
00162         TFT.circle(190,280,26,White);
00163         TFT.set_font((unsigned char*) Arial24x23);
00164         TFT.locate(40,84);
00165         TFT.printf("1");
00166         TFT.locate(40,144);
00167         TFT.printf("4");
00168         TFT.locate(40,204);
00169         TFT.printf("7");
00170         TFT.locate(110,84);
00171         TFT.printf("2");
00172         TFT.locate(110,144);
00173         TFT.printf("5");
00174         TFT.locate(110,204);
00175         TFT.printf("8");
00176         TFT.locate(180,84);
00177         TFT.printf("3");
00178         TFT.locate(180,144);
00179         TFT.printf("6");
00180         TFT.locate(180,204);
00181         TFT.printf("9");
00182         TFT.locate(110,264);
00183         TFT.printf("0");
00184         TFT.set_font((unsigned char*) Arial12x12);
00185         TFT.locate(110,104);
00186         TFT.printf("abc");
00187         TFT.locate(180,104);
00188         TFT.printf("def");
00189         TFT.locate(40,164);
00190         TFT.printf("ghi");
00191         TFT.locate(110,164);
00192         TFT.printf("jkl");
00193         TFT.locate(178,164);
00194         TFT.printf("mno");
00195         TFT.locate(36,224);
00196         TFT.printf("pqrs");
00197         TFT.locate(110,224);
00198         TFT.printf("tuv");
00199         TFT.locate(175,224);
00200         TFT.printf("wxyz");
00201         TFT.locate(110,284);
00202         TFT.printf("__");
00203         TFT.set_font((unsigned char*) Arial24x23);
00204         TFT.locate(180,270);
00205         TFT.printf("S");
00206         TFT.line(5,20,235,20,White);
00207         TFT.line(5,65,235,65,White);
00208         TFT.line(5,20,5,65,White);
00209         TFT.line(235,20,235,65,White);
00210     
00211 }
00212 
00213 
00214 int main()
00215 {
00216         int curr_x = 20;
00217         int curr_y = 5;
00218         int flag = 100;
00219         //Configure the display driver
00220         TFT.background(Black);
00221         TFT.foreground(White);
00222         TFT.cls();
00223         point p;
00224         keypad();
00225         char number[10];
00226         int in = 0;
00227         int j = 0;
00228         printf("HELLO SCA<M\n");
00229         while(1) {
00230             TFT.set_font((unsigned char*) Arial24x23);
00231             while(TFT.getTouch(p) != YES && TFT.getTouch(p) != MAYBE);
00232             
00233             while (TFT.getTouch(p) != NO && TFT.getTouch(p) != MAYBE) {
00234                 
00235                     //TFT.locate(50, 20);
00236                     //TFT.printf("%i %i",p.x,p.y);
00237                    
00238                     if((2000 < p.x && p.x < 3100) && (1500 < p.y && p.y < 2800)) {
00239                         flag = 1;
00240                         
00241                     }
00242                     else if((2000 < p.x && p.x < 3100) && (3300 < p.y && p.y < 4800)) {
00243                         flag = 2;
00244                         
00245                     }
00246                     else if((2000 < p.x && p.x < 3100) && (5300 < p.y && p.y < 6800)) {
00247                         flag = 3;
00248                         
00249                     }
00250                     else if((3300 < p.x && p.x < 4400) && (1500 < p.y && p.y < 2800))  {
00251                         flag = 4;
00252                         
00253                     }
00254                     else if((3300 < p.x && p.x < 4400) && (3300 < p.y && p.y < 4800)) {
00255                         flag = 5;
00256                     }
00257                     else if((3300 < p.x && p.x < 4400) && (5300 < p.y && p.y < 6800)) {
00258                         flag = 6;
00259                         
00260                     }
00261                     else if((4600 < p.x && p.x < 5700) && (1500 < p.y && p.y < 2800)) {
00262                         flag = 7;
00263                        
00264                     }
00265                     else if((4600 < p.x && p.x < 5700) && (3300 < p.y && p.y < 4800)) {
00266                         flag = 8;
00267                        
00268                     }
00269                     else if((4600 < p.x && p.x < 5700) && (5300 < p.y && p.y < 6800)) {
00270                         flag = 9;
00271                         
00272                     }
00273                     else if((5800 < p.x && p.x < 6900) && (3300 < p.y && p.y < 4800)) {
00274                         flag = 0;
00275                         
00276                     }
00277                     else if((5800 < p.x && p.x < 6900) && (1500 < p.y && p.y < 2800)) {
00278                         flag = 10;
00279                         
00280                     }
00281                     else if((5800 < p.x && p.x < 6900) && (5300 < p.y && p.y < 6800)) {
00282                         flag = 11;
00283                         
00284                     } 
00285                     else if((1000 < p.x && p.x < 2000) && (5300 < p.y && p.y < 6800)) {
00286                         flag = 20;
00287                     } 
00288                     else
00289                         flag = 100;
00290             }
00291             
00292             TFT.locate(curr_y,curr_x);
00293             if (flag == 1) {
00294                 
00295                 TFT.printf("%i",flag);
00296                 curr_y += 15;
00297                 number[in++] = flag;
00298                 wait_ms(30);
00299                 
00300             }
00301             else if (flag == 2) {
00302                
00303                 TFT.printf("%i",flag);
00304                 curr_y += 15;
00305                  number[in++] = flag;
00306                 wait_ms(30);
00307             }
00308             else if (flag == 3) {
00309                 number[in++] = flag;
00310                 TFT.printf("%i",flag);
00311                 curr_y += 15;
00312                 wait_ms(30);
00313             }
00314             else if (flag == 4) {
00315                
00316                 TFT.printf("%i",flag);
00317                 curr_y += 15;
00318                  number[in++] = flag;
00319                 wait_ms(30);
00320             }
00321             else if (flag == 5) {
00322                 
00323                 TFT.printf("%i",flag);
00324                 curr_y += 15;
00325                 number[in++] = flag;
00326                 wait_ms(30);
00327             }
00328             else if (flag == 6) {
00329                 
00330                 TFT.printf("%i",flag);
00331                 curr_y += 15;
00332                 number[in++] = flag;
00333                 wait_ms(30);
00334             }
00335             else if (flag == 7) {
00336                 
00337                 TFT.printf("%i",flag);
00338                 curr_y += 15;
00339                 number[in++] = flag;
00340                 wait_ms(30);
00341             }
00342             else if (flag == 8) {
00343                 
00344                 TFT.printf("%i",flag);
00345                 curr_y += 15;
00346                 number[in++] = flag;
00347                 wait_ms(30);
00348             }
00349             else if (flag == 9) {
00350                 
00351                 TFT.printf("%i",flag);
00352                 curr_y += 15;
00353                 number[in++] = flag;
00354                 wait_ms(30);
00355             }
00356             else if (flag == 0) {
00357                 
00358                 TFT.printf("%i",flag);
00359                 curr_y += 15;
00360                 number[in++] = flag;
00361                 wait_ms(30);
00362             }
00363             else if (flag == 20) {
00364                 
00365                 if(curr_y > 5){
00366                     curr_y -= 15;
00367                     TFT.locate(curr_y,curr_x);
00368                     TFT.printf(" ");
00369                     if (in > 0)
00370                     in--;
00371                 }
00372                 wait_ms(30);
00373             }
00374             else if (flag == 10) {
00375                 for (j=0;j<in;j++)
00376                     printf("%i",number[j]);
00377             }
00378             else {
00379             }
00380         }
00381         
00382         /*
00383         head();
00384         
00385         
00386         TFT.locate(50,280);
00387         TFT.printf("Call/Text");
00388         TFT.line(40,270,190,270,White);
00389         TFT.line(40,310,190,310,White);
00390         TFT.line(40,270,40,310,White);
00391         TFT.line(190,270,190,310,White);
00392         
00393         
00394         wait(5);
00395         keypad();
00396         
00397         wait(5);
00398         call();
00399         wait(5);
00400         text();
00401         wait(5);     
00402         */
00403         //Draw some graphics
00404         //TFT.cls();
00405         //TFT.set_font((unsigned char*) Arial24x23);
00406         //TFT.locate(100,100);
00407         //TFT.printf("Graphic");
00408     
00409         //TFT.line(0,0,100,0,White);
00410         //TFT.line(0,0,0,200,White);
00411         //TFT.line(0,0,100,200,White);
00412         //TFT.line(0,0,100,200,White);
00413     
00414         /*TFT.rect(100,50,150,100,Red);
00415         TFT.fillrect(180,25,220,70,Blue);*/
00416     
00417        
00418     /*
00419         double s;
00420         for (int i = 0; i < 320; i++) {
00421             s = 20 * sin((long double)i / 10);
00422             TFT.pixel(i, 100 + (int)s, Red);
00423         }
00424     
00425         //Wait for 5 seconds
00426         wait(5.0);
00427     
00428         //Multiple fonts
00429         TFT.foreground(White);
00430         TFT.background(Blue);
00431         TFT.cls();
00432         TFT.set_font((unsigned char*) Arial24x23);
00433         TFT.locate(0,0);
00434         TFT.printf("Different Fonts:");
00435         TFT.set_font((unsigned char*) Neu42x35);
00436         TFT.locate(0,30);
00437         TFT.printf("Hello Mbed 1");
00438         TFT.set_font((unsigned char*) Arial24x23);
00439         TFT.locate(20,80);
00440         TFT.printf("Hello Mbed 2");
00441         TFT.set_font((unsigned char*) Arial12x12);
00442         TFT.locate(35,120);
00443         TFT.printf("Hello Mbed 3");*/
00444     
00445 }