Skip to content

Commit 92633f7

Browse files
committed
adding circuitpython example for the tft featherwing 3.5 inch v2
1 parent 98f0a2b commit 92633f7

6 files changed

Lines changed: 69 additions & 0 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# SPDX-FileCopyrightText: 2023 Liz Clark for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
"""
5+
This test will initialize the display using displayio and display
6+
a bitmap image. The image advances when the touch screen is touched.
7+
8+
Pinouts are for the 3.5" TFT FeatherWing V2
9+
"""
10+
import os
11+
import board
12+
import displayio
13+
import adafruit_hx8357
14+
import adafruit_tsc2007
15+
16+
# Release any resources currently in use for the displays
17+
displayio.release_displays()
18+
19+
# Use Hardware SPI
20+
spi = board.SPI()
21+
22+
tft_cs = board.D9
23+
tft_dc = board.D10
24+
25+
display_width = 480
26+
display_height = 320
27+
28+
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)
29+
display = adafruit_hx8357.HX8357(display_bus, width=display_width, height=display_height)
30+
31+
i2c = board.STEMMA_I2C()
32+
33+
irq_dio = None
34+
tsc = adafruit_tsc2007.TSC2007(i2c, irq=irq_dio)
35+
36+
groups = []
37+
images = []
38+
for filename in os.listdir('/'):
39+
if filename.lower().endswith('.bmp') and not filename.startswith('.'):
40+
images.append("/"+filename)
41+
print(images)
42+
43+
for i in range(len(images)):
44+
splash = displayio.Group()
45+
bitmap = displayio.OnDiskBitmap(images[i])
46+
tile_grid = displayio.TileGrid(bitmap, pixel_shader=bitmap.pixel_shader)
47+
splash.append(tile_grid)
48+
groups.append(splash)
49+
50+
index = 0
51+
touch_state = False
52+
53+
display.root_group = groups[index]
54+
55+
while True:
56+
if tsc.touched and not touch_state:
57+
point = tsc.touch
58+
print("Touchpoint: (%d, %d, %d)" % (point["x"], point["y"], point["pressure"]))
59+
# left side of the screen
60+
if point["y"] < 2000:
61+
index = (index - 1) % len(images)
62+
display.root_group = groups[index]
63+
# right side of the screen
64+
else:
65+
index = (index + 1) % len(images)
66+
display.root_group = groups[index]
67+
touch_state = True
68+
if not tsc.touched and touch_state:
69+
touch_state = False
150 KB
Binary file not shown.
150 KB
Binary file not shown.
150 KB
Binary file not shown.
150 KB
Binary file not shown.
150 KB
Binary file not shown.

0 commit comments

Comments
 (0)