22//
33// SPDX-License-Identifier: MIT
44
5- #include " Adafruit_TestBed.h"
65#include < Arduino_GFX_Library.h>
7-
8- extern Adafruit_TestBed TB;
6+ #include < Adafruit_FT6206.h>
97
108Arduino_XCA9554SWSPI *expander = new Arduino_XCA9554SWSPI(
119 PCA_TFT_RESET, PCA_TFT_CS, PCA_TFT_SCK, PCA_TFT_MOSI,
@@ -18,7 +16,7 @@ Arduino_ESP32RGBPanel *rgbpanel = new Arduino_ESP32RGBPanel(
1816 TFT_B1, TFT_B2, TFT_B3, TFT_B4, TFT_B5,
1917 1 /* hsync_polarity */ , 50 /* hsync_front_porch */ , 2 /* hsync_pulse_width */ , 44 /* hsync_back_porch */ ,
2018 1 /* vsync_polarity */ , 16 /* vsync_front_porch */ , 2 /* vsync_pulse_width */ , 18 /* vsync_back_porch */
21- // ,1, 30000000
19+ // ,1, 30000000
2220 );
2321
2422Arduino_RGB_Display *gfx = new Arduino_RGB_Display(
@@ -50,7 +48,13 @@ Arduino_RGB_Display *gfx = new Arduino_RGB_Display(
5048// 1 /* vsync_polarity */, 50 /* vsync_front_porch */, 16 /* vsync_pulse_width */, 16 /* vsync_back_porch */
5149
5250uint16_t *colorWheel;
53-
51+
52+
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!
56+ bool touchOK = false ; // we will check if the touchscreen exists
57+
5458void setup (void )
5559{
5660 Serial.begin (115200 );
@@ -75,19 +79,37 @@ void setup(void)
7579 expander->pinMode (PCA_TFT_BACKLIGHT, OUTPUT);
7680 expander->digitalWrite (PCA_TFT_BACKLIGHT, HIGH);
7781
78- TB.begin ();
7982 colorWheel = (uint16_t *) ps_malloc (gfx->width () * gfx->height () * sizeof (uint16_t ));
80- if (colorWheel) generateColorWheel (colorWheel);
81- }
82-
83+ if (colorWheel) {
84+ generateColorWheel (colorWheel);
85+ gfx->draw16bitRGBBitmap (0 , 0 , colorWheel, gfx->width (), gfx->height ());
86+ }
8387
84- uint8_t allpins[] = {SS, SCK, MOSI, MISO, A1, A0};
88+ if (!ctp.begin (0 , &Wire, I2C_TOUCH_ADDR)) {
89+ Serial.println (" No touchscreen found" );
90+ touchOK = false ;
91+ } else {
92+ Serial.println (" Touchscreen found" );
93+ touchOK = true ;
94+ }
95+ }
8596
8697void loop ()
87- {
88- gfx->draw16bitRGBBitmap (0 , 0 , colorWheel, gfx->width (), gfx->height ());
89- delay (1000 );
90- return ;
98+ {
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);
103+ }
104+
105+ // use the buttons to turn off
106+ if (! expander->digitalRead (PCA_BUTTON_DOWN)) {
107+ expander->digitalWrite (PCA_TFT_BACKLIGHT, LOW);
108+ }
109+ // and on the backlight
110+ if (! expander->digitalRead (PCA_BUTTON_UP)) {
111+ expander->digitalWrite (PCA_TFT_BACKLIGHT, HIGH);
112+ }
91113}
92114
93115// https://chat.openai.com/share/8edee522-7875-444f-9fea-ae93a8dfa4ec
0 commit comments