|
4 | 4 |
|
5 | 5 | #include <Arduino_GFX_Library.h>
|
6 | 6 | #include <Adafruit_FT6206.h>
|
| 7 | +#include <Adafruit_CST8XX.h> |
7 | 8 |
|
8 | 9 | Arduino_XCA9554SWSPI *expander = new Arduino_XCA9554SWSPI(
|
9 | 10 | PCA_TFT_RESET, PCA_TFT_CS, PCA_TFT_SCK, PCA_TFT_MOSI,
|
@@ -49,11 +50,18 @@ Arduino_RGB_Display *gfx = new Arduino_RGB_Display(
|
49 | 50 |
|
50 | 51 | uint16_t *colorWheel;
|
51 | 52 |
|
| 53 | +// The Capacitive touchscreen overlays uses hardware I2C (SCL/SDA) |
52 | 54 |
|
53 |
| -// The FTxxxx based CTP overlays uses hardware I2C (SCL/SDA) |
54 |
| -#define I2C_TOUCH_ADDR 0x48 // often but not always 0x38! |
55 |
| -Adafruit_FT6206 ctp = Adafruit_FT6206(); // this library also supports FT5336U! |
| 55 | +// Most touchscreens use FocalTouch with I2C Address often but not always 0x48! |
| 56 | +#define I2C_TOUCH_ADDR 0x48 |
| 57 | + |
| 58 | +// 2.1" 480x480 round display use CST826 touchscreen with I2C Address at 0x15 |
| 59 | +//#define I2C_TOUCH_ADDR 0x15 // often but not always 0x48! |
| 60 | + |
| 61 | +Adafruit_FT6206 focal_ctp = Adafruit_FT6206(); // this library also supports FT5336U! |
| 62 | +Adafruit_CST8XX cst_ctp = Adafruit_CST8XX(); |
56 | 63 | bool touchOK = false; // we will check if the touchscreen exists
|
| 64 | +bool isFocalTouch = false; |
57 | 65 |
|
58 | 66 | void setup(void)
|
59 | 67 | {
|
@@ -85,21 +93,36 @@ void setup(void)
|
85 | 93 | gfx->draw16bitRGBBitmap(0, 0, colorWheel, gfx->width(), gfx->height());
|
86 | 94 | }
|
87 | 95 |
|
88 |
| - if (!ctp.begin(0, &Wire, I2C_TOUCH_ADDR)) { |
89 |
| - Serial.println("No touchscreen found"); |
90 |
| - touchOK = false; |
| 96 | + if (!focal_ctp.begin(0, &Wire, I2C_TOUCH_ADDR)) { |
| 97 | + // Try the CST826 Touch Screen |
| 98 | + if (!cst_ctp.begin(&Wire, I2C_TOUCH_ADDR)) { |
| 99 | + Serial.print("No Touchscreen found at address 0x"); |
| 100 | + Serial.println(I2C_TOUCH_ADDR, HEX); |
| 101 | + touchOK = false; |
| 102 | + } else { |
| 103 | + Serial.println("CST826 Touchscreen found"); |
| 104 | + touchOK = true; |
| 105 | + isFocalTouch = false; |
| 106 | + } |
91 | 107 | } else {
|
92 |
| - Serial.println("Touchscreen found"); |
| 108 | + Serial.println("Focal Touchscreen found"); |
93 | 109 | touchOK = true;
|
| 110 | + isFocalTouch = true; |
94 | 111 | }
|
95 | 112 | }
|
96 | 113 |
|
97 | 114 | void loop()
|
98 | 115 | {
|
99 |
| - if (touchOK && ctp.touched()) { |
100 |
| - TS_Point p = ctp.getPoint(0); |
101 |
| - Serial.printf("(%d, %d)\n", p.x, p.y); |
102 |
| - gfx->fillRect(p.x, p.y, 5, 5, WHITE); |
| 116 | + if (touchOK) { |
| 117 | + if (isFocalTouch && focal_ctp.touched()) { |
| 118 | + TS_Point p = focal_ctp.getPoint(0); |
| 119 | + Serial.printf("(%d, %d)\n", p.x, p.y); |
| 120 | + gfx->fillRect(p.x, p.y, 5, 5, WHITE); |
| 121 | + } else if (!isFocalTouch && cst_ctp.touched()) { |
| 122 | + CST_TS_Point p = cst_ctp.getPoint(0); |
| 123 | + Serial.printf("(%d, %d)\n", p.x, p.y); |
| 124 | + gfx->fillRect(p.x, p.y, 5, 5, WHITE); |
| 125 | + } |
103 | 126 | }
|
104 | 127 |
|
105 | 128 | // use the buttons to turn off
|
|
0 commit comments