Demo touching the perimeter of a circle

Dependencies:   RA8875

Revision:
1:e4f92c21e329
Parent:
0:f2a6447e607c
Child:
2:3077639f94fa
--- a/main.cpp	Sun Apr 04 16:50:35 2021 +0000
+++ b/main.cpp	Sun Apr 04 17:17:02 2021 +0000
@@ -33,24 +33,33 @@
 /// There are a few transformations (direction of rotation and angle
 /// offset) that didn't "feel right", even with the right result.
 ///
+/// NOTE NOTE NOTE NOTE NOTE NOTE
+///
+/// I didn't pay too much attention to managing int, float, and double
+/// to avoid unnecessary promotion or math complexity.
+///
 #include "mbed.h"
 #include "RA8875.h"
 
-/// Display with Capacitive Touch panel on I2C
+// Display with Capacitive Touch panel on I2C
 RA8875 lcd(p5,p6,p7,p12,NC, p9,p10,p13, "tft"); // MOSI,MISO,SCK,/ChipSelect,/reset, SDA,SCL,/IRQ, name
 //RA8875 lcd(p5,p6,p7,p8,NC, p28,p27,p30, "tft");
 
-
-Serial device(USBTX,USBRX);    // Not required for display
+// debug serial for printf. 
+// Some versions of the OS don't support the baud initializer here, then use device.baud(460800) in main.
+Serial device(USBTX,USBRX, 460800);    // Initialize to a fast baud
+//Serial device(p26,p25);
 
 // Screen size and color depth
 #define LCD_W 800
 #define LCD_H 480
-#define LCD_C 8         // color - bits per pixel
+#define LCD_C 8             // color - bits per pixel
+
+#define BL_NORM 100         // Backlight Normal setting (0 to 255)
 
-#define BL_NORM 100      // Backlight Normal setting (0 to 255)
-
+//
 // The Circle definition around which touches are relevant
+//
 const point_t center = {200,250};
 const dim_t radius = 125;
 const dim_t touch_tolerance = 30;
@@ -107,8 +116,9 @@
 
 int main()
 {
-    device.baud(460800);
-    device.printf("\r\n   RA8875 Touch Dial Example - Build " __DATE__ " " __TIME__ "\r\n");
+    //device.baud(460800);
+    printf("\r\n   RA8875 Touch Dial Example - Build " __DATE__ " " __TIME__ "\r\n");
+    printf("MBED v%d.%d.%d\r\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION);
 
     lcd.init(LCD_W,LCD_H,LCD_C,BL_NORM);
     lcd.TouchPanelInit();
@@ -117,8 +127,8 @@
     lcd.printf("RA8875 Touch Dial Example - Build " __DATE__ " " __TIME__ "\r\n");
     lcd.printf("MBED v%d.%d.%d\r\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION);
 
-    // Draw a thick circle
-    for (int r = -3; r <= 3; r++) {
+    // Draw a thickened circle
+    for (int r = 0; r <= 3; r++) {
         lcd.ellipse(center.x, center.y, radius + r, radius + r, BrightBlue);
     }
     
@@ -133,7 +143,7 @@
             // compute the angle to the touch from the center of the circle
             if (abs(GetRadius(Touch, center) - radius) <= touch_tolerance) {
                 int angle = GetAngle(Touch, center);
-                device.printf("Touch at (%4d,%4d) is %3d degrees from (%4d,%4d)\r\n", 
+                printf("Touch at (%4d,%4d) is %3d degrees from (%4d,%4d)\r\n", 
                     Touch.x, Touch.y, angle, center.x, center.y);
                 
                 // Fill the circle using 6° pie slices up to the angle of the touch
@@ -141,10 +151,10 @@
                 for (int a=6; a<=360; a+=6) {
                     point_t p = ProjectPoint(center, 90 - a, radius);
                     color_t fillColor = (a <= angle) ? Blue : Black;
-                    if ((a <= angle)) {     // show the triangle coordinates (only the fill)
-                        device.printf("    (%3d,%3d), (%3d,%3d), (%3d,%3d)\r\n",
-                            lastP.x,lastP.y, p.x,p.y, center.x,center.y);
-                    }
+                    //if ((a <= angle)) {     // show the triangle coordinates (only the fill)
+                    //    printf("    (%3d,%3d), (%3d,%3d), (%3d,%3d)\r\n",
+                    //        lastP.x,lastP.y, p.x,p.y, center.x,center.y);
+                    //}
                     lcd.filltriangle(center, p, lastP, fillColor);
                     lastP = p;
                 }