Paint for the FRDM-KL25Z

Dependencies:   mbed TFT_fonts SPI_TFT_ILI9341

Revision:
0:42ec9a44bc24
Child:
1:33506fcfdd95
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Jan 07 06:40:27 2019 +0000
@@ -0,0 +1,103 @@
+#include "mbed.h"
+#include "ILI932x.h"
+
+//#include "SDFileSystem.h"
+//#include "SPI.h"
+#include "BMP565.h"
+#include "Arial12x12.h"
+#include "stdio.h"
+#include "touch.h"
+ 
+// For better pressure precision, we need to know the resistance
+// between X+ and X- Use any multimeter to read it
+// The 2.8" TFT Touch shield has 300 ohms across the X plate
+    
+//Measured ADC values for (0,0) and (210-1,320-1)
+//TS_MINX corresponds to ADC value when X = 0
+//TS_MINY corresponds to ADC value when Y = 0
+//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
+#define PIN_XP PTA13  // can be a digital pin
+
+#define PIN_CS_TFT      PTB3
+#define PIN_RST_TFT     PTC2
+#define PIN_DC_TFT      PTB2
+#define PIN_WR_TFT      PTB1
+#define PIN_RD_TFT      PTB0
+
+#if 0
+#define PIN_CS_SD       PTD0
+#define PIN_MOSI        PTD2
+#define PIN_MISO        PTD3
+#define PIN_SCLK        PTD1
+#endif
+
+#define PIN_CS_TSC      PTD0
+#define PIN_MOSI        PTD2
+#define PIN_MISO        PTD3
+#define PIN_SCLK        PTD1
+
+PinName dataBus[] = {PTA13,PTD5,PTD4,PTA12,PTA4,PTA5,PTC8,PTC9};
+
+ILI932x TFT(BUS_8, dataBus, PIN_CS_TFT, PIN_RST_TFT, PIN_DC_TFT, PIN_WR_TFT, PIN_RD_TFT, "TFT", 240, 320);
+
+//SDFileSystem sd(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_SD, "sd");
+
+// Paint application - Demonstate both TFT and Touch Screen
+int ColorPaletteHigh = 30;
+int color = White;  //Paint brush color
+unsigned int colors[8] = {Red, Green, Blue, Cyan, Yellow, Black, White, LightGrey};
+
+
+TouchScreen tft(PIN_XP, PIN_YP, PIN_XM, PIN_YM); //init TouchScreen port pins
+
+
+int main(){
+    
+    TFT.claim(stdout);          // send stdout to the TFT display
+    TFT.set_orientation(0);
+    //TFT.Bitmap(28,90,265,65,p1);
+    //wait(1);
+    //TFT.cls();
+    TFT.set_font((unsigned char*) Arial12x12);
+    TFT.foreground(Cyan);      // set chars to Cyan
+    TFT.locate(80,90);
+    //printf("Initializing z...\r\n");
+    for(int i = 0; i<8; i++){
+        TFT.fillrect(i*30, 0, 30*(i+1), ColorPaletteHigh, colors[i]);
+    }
+    int zz=0;
+    while(1){
+        zz = zz + 1;
+        // a point object holds x y and z coordinates.
+        //Point p = tft.getPoint(p);
+        Point c(100,120,25);
+        //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);
+
+        // we have some minimum pressure we consider 'valid'
+        // pressure of 0 means no pressing!
+        TFT.locate(60,90);
+        printf("z = %d      \r\n", c.x);
+        TFT.locate(60,120);
+        printf("Initializing z...%d      \r\n",zz);
+        /*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