From 7d99cc8de629d21307703453716b813e6540f5c2 Mon Sep 17 00:00:00 2001 From: prenticedavid Date: Mon, 1 May 2017 15:32:40 +0100 Subject: [PATCH] radius variable, named colours --- examples/testcard_kbv/testcard_kbv.ino | 40 ++++++++++++++++---------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/examples/testcard_kbv/testcard_kbv.ino b/examples/testcard_kbv/testcard_kbv.ino index f2aa253..91bd0a9 100644 --- a/examples/testcard_kbv/testcard_kbv.ino +++ b/examples/testcard_kbv/testcard_kbv.ino @@ -21,8 +21,17 @@ MCUFRIEND_kbv tft; #define YELLOW 0xFFE0 #define WHITE 0xFFFF -#define GREY 0x7BEF +#define RGB(r, g, b) (((r&0xF8)<<8)|((g&0xFC)<<3)|(b>>3)) +#define GREY RGB(127, 127, 127) +#define DARKGREY RGB(64, 64, 64) +#define TURQUOISE RGB(0, 128, 128) +#define PINK RGB(255, 128, 192) +#define OLIVE RGB(128, 128, 0) +#define PURPLE RGB(128, 0, 128) +#define AZURE RGB(0, 128, 255) +#define ORANGE RGB(255,128,64) + #include uint16_t ID; @@ -58,7 +67,7 @@ void setup(void) void loop(void) { - int16_t x, y, dx, dy, idx; + int16_t x, y, dx, dy, radius = 108, idx; uint16_t w, h, len, mask; uint16_t colors[8] = { BLACK, WHITE, YELLOW, CYAN, GREEN, MAGENTA, RED, BLUE }; uint16_t height, width; @@ -85,20 +94,21 @@ void loop(void) for (x = 0, y = 3, w = 320, h = 1; y < 240; y += 18) { tft.fillRect(x, y, w, h, WHITE); } - tft.fillRect(26, 22, 17, 99, tft.color565(0, 128, 64)); //turq - tft.fillRect(26, 120, 17, 99, tft.color565(255, 128, 192)); //pink - tft.fillRect(44, 22, 17, 35, tft.color565(0, 128, 255)); //blue - tft.fillRect(44, 184, 17, 35, tft.color565(255, 128, 64)); //orng - tft.fillRect(260, 22, 17, 35, tft.color565(0, 128, 255)); //blue - tft.fillRect(260, 184, 17, 35, tft.color565(255, 128, 64)); //orng - tft.fillRect(278, 22, 17, 99, tft.color565(128, 128, 0)); //grn - tft.fillRect(278, 120, 17, 99, tft.color565(128, 0, 255)); //purp + tft.fillRect(26, 22, 17, 99, TURQUOISE); + tft.fillRect(26, 120, 17, 99, PINK); + tft.fillRect(44, 22, 17, 35, AZURE); + tft.fillRect(44, 184, 17, 35, ORANGE); + tft.fillRect(260, 22, 17, 35, AZURE); + tft.fillRect(260, 184, 17, 35, ORANGE); + tft.fillRect(278, 22, 17, 99, OLIVE); + tft.fillRect(278, 120, 17, 99, PURPLE); - for (dx = 111; dx > -111; dx--) { - w = sqrt(111 * 111 - dx * dx); + for (dx = radius; dx > -radius; dx--) { + w = sqrt(radius * radius - dx * dx); y = 120 - dx; dy = (y - 3) / 18; mask = 7; + colors[0] = (dy == 3) ? DARKGREY : BLACK; switch (dy) { case 0: case 1: idx = 1; len = 0; break; @@ -110,7 +120,8 @@ void loop(void) case 7: case 8: idx = 0; len = 0; break; case 9: for (idx = 2; idx < 8; idx++) { - dy = 0xFF >> (7 - idx); + //dy = 0xFF >> (7 - idx); + dy = (idx - 2) * 51; colors[idx] = tft.color565(dy, dy, dy); } idx = 2; len = 38; break; @@ -149,7 +160,7 @@ void loop(void) tft.fillRect(160, 5 * 18 + 3, 1, 3 * 18, WHITE); tft.fillRect(108, 2 * 18 + 3, 6 * 18, 18, WHITE); // tft.fillRect(108, 10 * 18 + 3, 6 * 18, 18, BLACK); - tft.fillRect(160 - 8, 11 * 18 + 3, 17, 31, RED); + tft.fillRect(160 - 8, 11 * 18 + 3, 17, radius - 18*9/2, RED); tft.setCursor(160 - 36, 24 + ADJ_BASELINE); tft.setTextColor(BLACK); tft.setTextSize(1); @@ -180,4 +191,3 @@ void loop(void) delay(1000); } } -