Skip to content

Commit f87701d

Browse files
authored
Merge pull request #13 from makermelissa/master
Add PiTFT example
2 parents 670633d + 0a426f4 commit f87701d

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

examples/hx8357_pitft_simpletest.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"""
2+
This test will initialize the display using displayio and draw a solid green
3+
background, a smaller purple rectangle, and some yellow text.
4+
"""
5+
6+
import board
7+
import terminalio
8+
import displayio
9+
from adafruit_display_text import label
10+
from adafruit_hx8357 import HX8357
11+
12+
# Release any resources currently in use for the displays
13+
displayio.release_displays()
14+
15+
spi = board.SPI()
16+
tft_cs = board.CE0
17+
tft_dc = board.D25
18+
19+
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)
20+
21+
display = HX8357(display_bus, width=480, height=320)
22+
23+
# Make the display context
24+
splash = displayio.Group(max_size=10)
25+
display.show(splash)
26+
27+
color_bitmap = displayio.Bitmap(display.width, display.height, 1)
28+
color_palette = displayio.Palette(1)
29+
color_palette[0] = 0x00FF00 # Bright Green
30+
31+
bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
32+
splash.append(bg_sprite)
33+
34+
# Draw a smaller inner rectangle
35+
inner_bitmap = displayio.Bitmap(display.width - 40, display.height - 40, 1)
36+
inner_palette = displayio.Palette(1)
37+
inner_palette[0] = 0xAA0088 # Purple
38+
inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=20, y=20)
39+
splash.append(inner_sprite)
40+
41+
# Draw a label
42+
text_group = displayio.Group(max_size=10, scale=3, x=137, y=160)
43+
text = "Hello World!"
44+
text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00)
45+
text_group.append(text_area) # Subgroup for text scaling
46+
splash.append(text_group)
47+
48+
while True:
49+
pass

0 commit comments

Comments
 (0)