micro paint to show the touchscreen and tft handling

Dependencies:   mbed Touch_tft TFT_fonts_old

Dependents:   touch_piirto

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "SPI_TFT.h"
00003 #include "Arial12x12.h"
00004 #include "Arial28x28.h"
00005 #include "touch_tft.h"
00006 
00007 
00008 // the TFT is connected to SPI pin 5-7
00009 // the touch is connected to 19,20,16,17
00010 
00011 touch_tft tt(p19,p20,p16,p17,p11, p12, p13, p14, p15,"TFT"); // x+,x-,y+,y-,mosi, miso, sclk, cs, reset
00012 
00013 int main() {
00014 
00015     unsigned short color = White;
00016     unsigned int brush = 2;
00017     point p;
00018 
00019     tt.claim(stdout);        // send stdout to the TFT display
00020     tt.background(Black);    // set background to black
00021     tt.foreground(White);    // set chars to white
00022     tt.cls();                // clear the screen
00023     tt.set_font((unsigned char*) Arial12x12);  // select the font
00024     tt.set_orientation(1);
00025 
00026     tt.calibrate();          // calibrate the touch
00027     tt.locate(0,0);
00028     printf(" x = ");
00029     tt.locate(0,12);
00030     printf(" y = ");
00031     tt.line(0,25,319,25,White);
00032     // the color chosing fields
00033     tt.fillrect(80,0,98,24,White);
00034     tt.fillrect(100,0,118,24,Green);
00035     tt.fillrect(120,0,138,24,Red);
00036     tt.fillrect(140,0,158,24,Blue);
00037     tt.line(179,0,179,24,White);
00038     // the brushes
00039     tt.fillcircle(190,12,2,White);
00040     tt.fillcircle(210,12,4,White);
00041     tt.fillcircle(230,12,6,White);
00042     tt.fillcircle(250,12,brush,color);
00043     while (1) {
00044 
00045         p = tt.get_touch();
00046         if (tt.is_touched(p)) {  // touch
00047         
00048             p = tt.to_pixel(p);          // convert to pixel pos
00049             if (p.y < 26) {        // a button field
00050                 if (p.x > 80 && p.x < 100) {  // White
00051                     color = White;
00052                 }
00053                 if (p.x > 100 && p.x < 120) {  // Green
00054                     color = Green;
00055                 }
00056                 if (p.x > 120 && p.x < 140) {  // Red
00057                     color = Red;
00058                 }
00059                 if (p.x > 140 && p.x < 160) {  // Blue
00060                     color = Blue;
00061                 }
00062                 if (p.x > 160 && p.x < 180) {  // Black
00063                     color = Black;
00064                 }
00065                 if (p.x > 180 && p.x < 200) {  // brush 2
00066                     brush = 2;
00067                 }
00068                 if (p.x > 200 && p.x < 220) {  // brush 4
00069                     brush = 4;
00070                 }
00071                 if (p.x > 220 && p.x < 240) {  // brush 6
00072                     brush = 6;
00073                 }
00074                 if (color != Black) {
00075                     tt.fillrect(240,0,260,24,Black);
00076                 } else {
00077                     tt.fillrect(240,0,260,24,White);
00078                 }
00079                 tt.fillcircle(250,12,brush,color);
00080                 if (p.x > 300) {
00081                     tt.fillrect(0,26,319,239,Black);
00082                 }
00083    
00084             } else {
00085                 tt.fillcircle(p.x,p.y,brush,color);
00086                 tt.locate(36,0);
00087                 printf("%3d",p.x);
00088                 tt.locate(36,12);
00089                 printf("%3d",p.y);
00090             }
00091         }
00092 
00093     }
00094 
00095 }
00096 
00097 
00098 
00099