aivan upea mahtava piirto-ohjelma

Dependencies:   SPI_TFT_ILI9341 TFT_fonts mbed touch

Fork of touch by Peter Drescher

Revision:
3:30b085fb4f1a
Parent:
2:9d80fd43a008
--- a/main.cpp	Sun Sep 04 21:49:22 2011 +0000
+++ b/main.cpp	Thu Jan 16 06:45:39 2014 +0000
@@ -1,5 +1,5 @@
 #include "mbed.h"
-#include "SPI_TFT.h"
+#include "SPI_TFT_ILI9341.h"
 #include "Arial12x12.h"
 #include "Arial28x28.h"
 #include "touch_tft.h"
@@ -8,12 +8,13 @@
 // the TFT is connected to SPI pin 5-7
 // the touch is connected to 19,20,16,17
 
-touch_tft tt(p19,p20,p16,p17,p11, p12, p13, p14, p15,"TFT"); // x+,x-,y+,y-,mosi, miso, sclk, cs, reset
+touch_tft tt(p20,p19,p18,p17,p5, p6, p7, p14, p15, p21, "TFT"); // x+,x-,y+,y-,mosi, miso, sclk, cs, reset, dc
 
 int main() {
 
     unsigned short color = White;
     unsigned int brush = 2;
+    unsigned int apu = 0;    //apumuuttuja neliöbrushin tarkastamiseen
     point p;
 
     tt.claim(stdout);        // send stdout to the TFT display
@@ -29,17 +30,20 @@
     tt.locate(0,12);
     printf(" y = ");
     tt.line(0,25,319,25,White);
+    
     // the color chosing fields
     tt.fillrect(80,0,98,24,White);
     tt.fillrect(100,0,118,24,Green);
     tt.fillrect(120,0,138,24,Red);
     tt.fillrect(140,0,158,24,Blue);
-    tt.line(179,0,179,24,White);
+    tt.fillrect(160,0,178,24,Yellow);
+    tt.line(199,0,199,24,White);
     // the brushes
-    tt.fillcircle(190,12,2,White);
-    tt.fillcircle(210,12,4,White);
-    tt.fillcircle(230,12,6,White);
-    tt.fillcircle(250,12,brush,color);
+    tt.fillcircle(210,12,2,White);
+    tt.fillcircle(230,12,4,White);
+    tt.fillcircle(250,12,6,White);
+    tt.fillrect(266,5,280,19,White); //neliö brush
+ 
     while (1) {
 
         p = tt.get_touch();
@@ -59,29 +63,52 @@
                 if (p.x > 140 && p.x < 160) {  // Blue
                     color = Blue;
                 }
-                if (p.x > 160 && p.x < 180) {  // Black
+                if (p.x > 160 && p.x < 180) {  // Yellow
+                    color = Yellow;
+                }
+                if (p.x > 180 && p.x < 200) {  // Black
                     color = Black;
                 }
-                if (p.x > 180 && p.x < 200) {  // brush 2
+                if (p.x > 200 && p.x < 220) {  // brush 2
                     brush = 2;
+                    apu = 0;
                 }
-                if (p.x > 200 && p.x < 220) {  // brush 4
+                if (p.x > 220 && p.x < 240) {  // brush 4
                     brush = 4;
+                    apu = 0;
                 }
-                if (p.x > 220 && p.x < 240) {  // brush 6
+                if (p.x > 240 && p.x < 260) {  // brush 6
                     brush = 6;
+                    apu = 0;
                 }
+                
                 if (color != Black) {
-                    tt.fillrect(240,0,260,24,Black);
+                    tt.fillrect(298,0,318,24,Black);
                 } else {
-                    tt.fillrect(240,0,260,24,White);
+                    tt.fillrect(298,0,318,24,White);
                 }
-                tt.fillcircle(250,12,brush,color);
-                if (p.x > 300) {
+                
+                if (p.x > 260 && p.x < 290) {               //valittu brush
+                    tt.fillrect(302,5,316,19,color);
+                    apu = 1;
+                }
+                else {
+                    tt.fillcircle(308,12,brush,color);
+                }
+                
+                if (p.x < 20) {                            //tyhjentää näytön
                     tt.fillrect(0,26,319,239,Black);
                 }
+                
    
-            } else {
+            } else if (apu == 1) {                          //piirtää neliöllä
+                tt.fillrect(p.x-7,p.y-7,p.x+7,p.y+7,color);
+                tt.locate(36,0);
+                printf("%3d",p.x);
+                tt.locate(36,12);
+                printf("%3d",p.y);                          
+            }
+            else {                                          //piirtää ympyrällä
                 tt.fillcircle(p.x,p.y,brush,color);
                 tt.locate(36,0);
                 printf("%3d",p.x);