diff --git a/TFT_FeatherWing_TSC2007_Demos/Arduino_TouchPaint_TSC2007/.feather_rp2040.test.only b/TFT_FeatherWing_TSC2007_Demos/Arduino_TouchPaint_TSC2007/.feather_rp2040.test.only new file mode 100644 index 000000000..e69de29bb diff --git a/TFT_FeatherWing_TSC2007_Demos/Arduino_TouchPaint_TSC2007/Arduino_TouchPaint_TSC2007.ino b/TFT_FeatherWing_TSC2007_Demos/Arduino_TouchPaint_TSC2007/Arduino_TouchPaint_TSC2007.ino new file mode 100644 index 000000000..43f73c52c --- /dev/null +++ b/TFT_FeatherWing_TSC2007_Demos/Arduino_TouchPaint_TSC2007/Arduino_TouchPaint_TSC2007.ino @@ -0,0 +1,127 @@ +// SPDX-FileCopyrightText: 2023 Limor Fried/Ladyada for Adafruit Industries +// SPDX-License-Identifier: MIT + +/*************************************************** + This is our touchscreen painting example for the updated Adafruit + TFT FeatherWing V2 with TSC2007 + ----> http://www.adafruit.com/products/3315 + + Adafruit invests time and resources providing this open source code, + please support Adafruit and open-source hardware by purchasing + products from Adafruit! + + Written by Limor Fried/Ladyada for Adafruit Industries. + MIT license, all text above must be included in any redistribution + ****************************************************/ + + +#include +#include +#include +#include +#include + +// This is calibration data for the raw touch data to the screen coordinates +#define TS_MINX 150 +#define TS_MINY 130 +#define TS_MAXX 3800 +#define TS_MAXY 4000 +#define TS_MIN_PRESSURE 200 + +Adafruit_TSC2007 ts; + +// The display also uses hardware SPI, plus #9 & #10 +#define TFT_CS 9 +#define TFT_DC 10 +Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); + +// Size of the color selection boxes and the paintbrush size +#define BOXSIZE 40 +#define PENRADIUS 3 +int oldcolor, currentcolor; + +void setup(void) { + + Serial.begin(115200); + // while (!Serial) delay(10); + + tft.begin(); + + if (!ts.begin()) { + Serial.println("Couldn't start touchscreen controller"); + while (1); + } + Serial.println("Touchscreen started"); + + tft.fillScreen(ILI9341_BLACK); + + // make the color selection boxes + tft.fillRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_RED); + tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_YELLOW); + tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_GREEN); + tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_CYAN); + tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_BLUE); + tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_MAGENTA); + + // select the current color 'red' + tft.drawRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE); + currentcolor = ILI9341_RED; +} + +void loop(){ + uint16_t x, y, z1, z2; + if (ts.read_touch(&x, &y, &z1, &z2) && (z1 > TS_MIN_PRESSURE)) { + + Serial.print("Touch point: ("); + Serial.print(x); Serial.print(", "); + Serial.print(y); Serial.print(", "); + Serial.print(z1); Serial.print(" / "); + Serial.print(z2); Serial.println(")"); + + // Scale from ~0->4000 to tft.width using the calibration #'s + x = map(x, TS_MINX, TS_MAXX, 0, tft.width()); + y = map(y, TS_MINY, TS_MAXY, 0, tft.height()); + + if (y < BOXSIZE) { + oldcolor = currentcolor; + + if (x < BOXSIZE) { + currentcolor = ILI9341_RED; + tft.drawRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE); + } else if (x < BOXSIZE*2) { + currentcolor = ILI9341_YELLOW; + tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE); + } else if (x < BOXSIZE*3) { + currentcolor = ILI9341_GREEN; + tft.drawRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE); + } else if (x < BOXSIZE*4) { + currentcolor = ILI9341_CYAN; + tft.drawRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE); + } else if (x < BOXSIZE*5) { + currentcolor = ILI9341_BLUE; + tft.drawRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE); + } else if (x < BOXSIZE*6) { + currentcolor = ILI9341_MAGENTA; + tft.drawRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE); + } + + if (oldcolor != currentcolor) { + if (oldcolor == ILI9341_RED) + tft.fillRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_RED); + if (oldcolor == ILI9341_YELLOW) + tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_YELLOW); + if (oldcolor == ILI9341_GREEN) + tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_GREEN); + if (oldcolor == ILI9341_CYAN) + tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_CYAN); + if (oldcolor == ILI9341_BLUE) + tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_BLUE); + if (oldcolor == ILI9341_MAGENTA) + tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_MAGENTA); + } + } + if (((y-PENRADIUS) > BOXSIZE) && ((y+PENRADIUS) < tft.height())) { + tft.fillCircle(x, y, PENRADIUS, currentcolor); + } + } +} diff --git a/TFT_FeatherWing_TSC2007_Demos/CircuitPython/code.py b/TFT_FeatherWing_TSC2007_Demos/CircuitPython/code.py new file mode 100644 index 000000000..c2c9ba604 --- /dev/null +++ b/TFT_FeatherWing_TSC2007_Demos/CircuitPython/code.py @@ -0,0 +1,69 @@ +# SPDX-FileCopyrightText: 2023 Liz Clark for Adafruit Industries +# SPDX-License-Identifier: MIT + +""" +This test will initialize the display using displayio and display +a bitmap image. The image advances when the touch screen is touched. + +Pinouts are for the 2.4" TFT FeatherWing V2 +""" +import os +import board +import displayio +import adafruit_ili9341 +import adafruit_tsc2007 + +# Release any resources currently in use for the displays +displayio.release_displays() + +# Use Hardware SPI +spi = board.SPI() + +tft_cs = board.D9 +tft_dc = board.D10 + +display_width = 320 +display_height = 240 + +display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs) +display = adafruit_ili9341.ILI9341(display_bus, width=display_width, height=display_height) + +i2c = board.STEMMA_I2C() + +irq_dio = None +tsc = adafruit_tsc2007.TSC2007(i2c, irq=irq_dio) + +groups = [] +images = [] +for filename in os.listdir('/'): + if filename.lower().endswith('.bmp') and not filename.startswith('.'): + images.append("/"+filename) +print(images) + +for i in range(len(images)): + splash = displayio.Group() + bitmap = displayio.OnDiskBitmap(images[i]) + tile_grid = displayio.TileGrid(bitmap, pixel_shader=bitmap.pixel_shader) + splash.append(tile_grid) + groups.append(splash) + +index = 0 +touch_state = False + +display.show(groups[index]) + +while True: + if tsc.touched and not touch_state: + point = tsc.touch + print("Touchpoint: (%d, %d, %d)" % (point["x"], point["y"], point["pressure"])) + # left side of the screen + if point["y"] < 2000: + index = (index - 1) % len(images) + display.show(groups[index]) + # right side of the screen + else: + index = (index + 1) % len(images) + display.show(groups[index]) + touch_state = True + if not tsc.touched and touch_state: + touch_state = False diff --git a/TFT_FeatherWing_TSC2007_Demos/CircuitPython/cp_5.bmp b/TFT_FeatherWing_TSC2007_Demos/CircuitPython/cp_5.bmp new file mode 100644 index 000000000..25e34560c Binary files /dev/null and b/TFT_FeatherWing_TSC2007_Demos/CircuitPython/cp_5.bmp differ diff --git a/TFT_FeatherWing_TSC2007_Demos/CircuitPython/cp_6.bmp b/TFT_FeatherWing_TSC2007_Demos/CircuitPython/cp_6.bmp new file mode 100644 index 000000000..a1bacb3ff Binary files /dev/null and b/TFT_FeatherWing_TSC2007_Demos/CircuitPython/cp_6.bmp differ diff --git a/TFT_FeatherWing_TSC2007_Demos/CircuitPython/cp_7.bmp b/TFT_FeatherWing_TSC2007_Demos/CircuitPython/cp_7.bmp new file mode 100644 index 000000000..606ecaa69 Binary files /dev/null and b/TFT_FeatherWing_TSC2007_Demos/CircuitPython/cp_7.bmp differ diff --git a/TFT_FeatherWing_TSC2007_Demos/CircuitPython/cp_8.bmp b/TFT_FeatherWing_TSC2007_Demos/CircuitPython/cp_8.bmp new file mode 100644 index 000000000..9515ac512 Binary files /dev/null and b/TFT_FeatherWing_TSC2007_Demos/CircuitPython/cp_8.bmp differ diff --git a/TFT_FeatherWing_TSC2007_Demos/CircuitPython/cp_9.bmp b/TFT_FeatherWing_TSC2007_Demos/CircuitPython/cp_9.bmp new file mode 100644 index 000000000..184e45095 Binary files /dev/null and b/TFT_FeatherWing_TSC2007_Demos/CircuitPython/cp_9.bmp differ