Example drawing mandelbrot on the RA8875 with touch to zoom in or out. Touch and hold > 4s to zoom out, touch to zoom in.

Dependencies:   mbed RA8875

Saw the nice mandelbrot demo from Bob Stone and leverage it to use this library.

Revision:
5:3efba02a1cb2
Parent:
4:857e3bf77211
Child:
6:3979c5ff6d32
--- a/main.cpp	Sat Jan 23 17:29:55 2016 +0000
+++ b/main.cpp	Mon Mar 04 12:11:39 2019 +0000
@@ -1,9 +1,27 @@
 #include "mbed.h"       // v112
 #include "RA8875.h"     // v102
 
-LocalFileSystem local("local"); //file system
+// These two defines can be enabled, or commented out
+#define BIG_SCREEN
+#define CAP_TOUCH
+#define LCD_C 16         // color - bits per pixel
+
+#ifdef CAP_TOUCH
+RA8875 lcd(p5, p6, p7, p12, NC, p9,p10,p13, "tft"); // MOSI,MISO,SCK,/ChipSelect,/reset, SDA,SCL,/IRQ, name
+#else
+RA8875 lcd(p5, p6, p7, p12, NC, "tft");             //MOSI, MISO, SCK, /ChipSelect, /reset, name
+LocalFileSystem local("local");                     // access to calibration file for resistive touch.
+#endif
+
+#ifdef BIG_SCREEN
+    #define LCD_W 800
+    #define LCD_H 480
+#else
+    #define LCD_W 480
+    #define LCD_H 272
+#endif
+
 Serial pc(USBTX, USBRX);
-RA8875 lcd(p5, p6, p7, p12, NC, "tft");    // MOSI, MISO, SCK, /ChipSelect, /reset, name
 
 uint16_t width, height;
 
@@ -32,7 +50,7 @@
     float xmin = centrex - 1.0/zoom;
     float xmax = centrex + 1.0/zoom;
     float ymin = centrey - height / (width * zoom);
-    float ymax = centrey + height / (width *zoom);
+    float ymax = centrey + height / (width * zoom);
     float dx = (xmax - xmin) / width;
     float dy = (ymax - ymin) / height;
     float y = ymin;
@@ -94,8 +112,13 @@
     pc.printf("\r\nRA8875 Portrait Mode Dev. - Build " __DATE__ " " __TIME__ "\r\n");
     pc.printf("Press 'P' to PrintScreen as bmp on local file system\r\n");
     
-    lcd.init();
-    lcd.frequency(10000000);
+    lcd.init(LCD_W, LCD_H, LCD_C);
+    lcd.Backlight(0.5f);
+    
+    #ifndef CAP_TOUCH
+    InitTS();
+    #endif
+
     width = lcd.width();        // Could have set the dimensions, let's just adapt.
     height = lcd.height();
 
@@ -103,10 +126,7 @@
     lcd.background(Black);    // set background to black
     lcd.foreground(White);    // set chars to white
     lcd.cls();                // clear the screen
-    lcd.TouchPanelCalibrate("Touch to Calibrate,\r\nthen touch to zoom in,\r\nand touch-hold to zoom out.");
- 
-    //lcd.locate(0,0);
- 
+  
     //Setup base Mandelbrot
     float centrex = -0.5;
     float centrey = 0.0;
@@ -120,21 +140,29 @@
         pc.printf("ready for touch\r\n");
         bool waitingOnUser = true;
         while (waitingOnUser) {
+            TouchCode_t t;
+            
             if (pc.readable()) {
                 int c = pc.getc();
                 if (c == 'P')
                     GetScreenCapture();
             }
-            if (lcd.TouchPanelReadable()) {
+            t = lcd.TouchPanelReadable();
+            if (t != no_touch) {
                 bool zoomOut = false;
                 
+                pc.printf("touch: %d\r\n", t);
                 timer.start();
                 timer.reset();
-                while (lcd.TouchPanelReadable(&p)) {
+                t = lcd.TouchPanelReadable(&p);
+                pc.printf(" t: %d\r\n", t);
+                while (t == touch || t == held) {
                     if (timer.read_ms() > 2000) {
                         zoomOut = true;
                         break;
                     }
+                    t = lcd.TouchPanelReadable(&p);
+                    pc.printf(" u: %d\r\n", t);
                 }
                 if (zoomOut) {   // long held is zoom out.
                     // zoom out