Paint for the FRDM-KL25Z

Dependencies:   mbed TFT_fonts SPI_TFT_ILI9341

Revision:
2:fe018965e46c
Parent:
1:33506fcfdd95
Child:
3:1396bac4ae71
--- a/main.cpp	Mon Jan 07 16:15:52 2019 +0000
+++ b/main.cpp	Tue Jan 08 06:56:55 2019 +0000
@@ -18,11 +18,6 @@
 //TS_MAXX corresponds to ADC value when X = 240 -1
 //TS_MAXY corresponds to ADC value when Y = 320 -1
 
-#define TS_MINX 116*2
-#define TS_MAXX 890*2
-#define TS_MINY 83*2
-#define TS_MAXY 913*2
-
 #define PIN_YP PTB3  // must be an analog pin, use "An" notation!
 #define PIN_XM PTB2  // must be an analog pin, use "An" notation!
 #define PIN_YM PTD5   // can be a digital pin
@@ -80,16 +75,24 @@
     
 Point getPoint(){
     PinName _yp, _ym, _xm, _xp;
-    int z = 0;
-    int y2 = tft.readTouch(_xp,_xm,_yp,_ym);
-    int x2 = tft.readTouch(_yp,_ym,_xm,_xp);
+    int z;
+    int RXPLATE = 350;
+    int Q = 1024;  //10 bit TSC Resolution
+    /*int y2 = tft.readTouch(PIN_XP, PIN_YP, PIN_XM, PIN_YM);
+    /*int x2 = tft.readTouch(_yp,_ym,_xm,_xp);
     int y1 = tft.readTouch(_xp,_xm,_ym,_yp);
     int x1 = tft.readTouch(_yp,_ym,_xp,_xm);
     int z2 = tft.readTouch(_ym,_xp,_yp,_xm);
-    int z1 = tft.readTouch(_ym,_xp,_xm,_yp);
+    int z1 = tft.readTouch(_ym,_xp,_xm,_yp);*/
+    
+    int y2 = 700;
+    int x2 = 600;
+    int z2 = 110;
+    int z1 = 100;
+    
 
     if (z1!=0){
-        z = RXPLATE*x2/Q*(z2/z1-1);
+        z = (float)RXPLATE/(float)Q*x2*((float)z2/(float)z1-1);
     }else{
         z = 0;
     }
@@ -113,28 +116,37 @@
     for(int i = 0; i<8; i++){
         TFT.fillrect(i*30, 0, 30*(i+1), ColorPaletteHigh, colors[i]);
     }
-    int zz=0;
+    int zx=0;
+    float TS_MINX = 116;
+    float TS_MAXX = 890;
+    float TS_MINY = 83;
+    float TS_MAXY = 913;
+    int PRESSURE = 10;
     while(1){
-        zz = zz + 1;
+        zx = zx + 1;
         // a point object holds x y and z coordinates.
-        //Point p = getPoint();
+        Point p = getPoint();
         //map the ADC value read to into pixel co-ordinates
-        //p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240);
-        //p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320);
+        p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240);
+        p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320);
 
         // we have some minimum pressure we consider 'valid'
         // pressure of 0 means no pressing!
-        //TFT.locate(60,90);
-        //printf("z = %d      \r\n", p.x);
-        TFT.locate(60,120);
-        printf("Initializing z...%d      \r\n",zz);
-        /*if (p.z > PRESSURE) {
+        TFT.locate(60,90);
+        printf("x = %d      \r\n", p.x);
+        TFT.locate(60,110);
+        printf("y = %d      \r\n", p.y);
+        TFT.locate(60,130);
+        printf("z = %d      \r\n", p.z);
+        TFT.locate(60,170);
+        printf("Initializing z...%d      \r\n",zx);
+        if (p.z > PRESSURE) {
             // Detect  paint brush color change
             if(p.y < ColorPaletteHigh+2){
                 color = colors[p.x/30];
             }else{
                 TFT.fillcircle(p.x,p.y,2,color);
             }
-        }*/
+        }
     }
 }
\ No newline at end of file