David Smart
/
PUB_RA8875_TouchColors
An example program using the RA8875 Display controller with the touch-screen option.
Diff: main.cpp
- Revision:
- 0:2b1669e97586
- Child:
- 1:47e5fbdb28f1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Dec 28 22:02:36 2014 +0000 @@ -0,0 +1,84 @@ + +#include "mbed.h" // tested with v92 +#include "RA8875.h" // tested with v80 + +LocalFileSystem local("local"); +RA8875 lcd(p5, p6, p7, p12, NC, "tft"); // MOSI, MISO, SCK, /ChipSelect, /reset, name +Serial pc(USBTX, USBRX); + +extern "C" void mbed_reset(); + + +#define min(a,b) ((a<b)?a:b) +#define max(a,b) ((a>b)?a:b) + +bool Intersect(rect_t rect, point_t p) +{ + if (p.x >= min(rect.p1.x, rect.p2.x) && p.x <= max(rect.p1.x, rect.p2.x) + && p.y >= min(rect.p1.y, rect.p2.y) && p.y <= max(rect.p1.y, rect.p2.y)) + return true; + else + return false; +} + +int main() +{ + pc.baud(460800); // I like a snappy terminal, so crank it up! + pc.printf("\r\nRA8875 Touch Colors - Build " __DATE__ " " __TIME__ "\r\n"); + + pc.printf("Turning on display\r\n"); + lcd.init(); + lcd.TouchPanelCalibrate("Calibrate the touch panel"); + lcd.cls(); + + // +----------------------------------------------------+ + // | (x,y) (xxx,yyy) rgb (RR,GG,BB) | + // | +------------------------------------------------+ | y = 50 + // | | Sample Shown Here | | + // | +------------------------------------------------+ | y = 89 + // | Red 0 to 255 ------------------------------------+ | y = 100 + // | | | | + // | +------------------------------------------------+ | y = 139 + // | Grn 0 to 255 ------------------------------------+ | y = 150 + // | | | | + // | +------------------------------------------------+ | y = 189 + // | Blu 0 to 255 ------------------------------------+ | y = 200 + // | | | | + // | +------------------------------------------------+ | y = 239 + // +----------------------------------------------------+ y = 271 + // 10 470 + rect_t RGBList[] = { + { 10,100, 470,139 }, // R + { 10,150, 470,189 }, // G + { 10,200, 470,239 }, // B + { 10, 50, 470, 89 } // This for the Sample + }; + lcd.fillrect(RGBList[0], Red); + lcd.fillrect(RGBList[1], Green); + lcd.fillrect(RGBList[2], Blue); + color_t rgb = Black; + uint8_t rgbVal[3] = { 0, 0, 0 }; + + for (;;) { + point_t p; + + if (lcd.TouchPanelReadable(&p)) { + lcd.foreground(Blue); + lcd.SetTextCursor(10, 15); + lcd.printf("(%3d,%3d)", p.x, p.y); + + for (int i=0; i<3; i++) { + if (Intersect(RGBList[i], p)) { + uint8_t mag = (255 * (p.x - RGBList[i].p1.x)) / (RGBList[i].p2.x - RGBList[i].p1.x); + rgbVal[i] = mag; + lcd.SetTextCursor(380, 15); + lcd.foreground(Blue); + lcd.printf("(%02X,%02X,%02X)", rgbVal[0], rgbVal[1], rgbVal[2]); + rgb = RGB(rgbVal[0], rgbVal[1], rgbVal[2]); + lcd.fillrect(RGBList[3], rgb); + break; + } + } + } + } +}