Skip to content

Commit c0c8985

Browse files
authored
Create st7789_240x135_simpletest_Pimoroni_Pico_Display_Pack.py
Adding functionality simply for Pimoroni Pico Display Pack
1 parent ee92f2f commit c0c8985

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import board
2+
import busio
3+
import terminalio
4+
import displayio
5+
from adafruit_display_text import label
6+
from adafruit_st7789 import ST7789
7+
8+
# First set some parameters used for shapes and text
9+
BORDER = 20
10+
FONTSCALE = 2
11+
BACKGROUND_COLOR = 0x00FF00 # Bright Green
12+
FOREGROUND_COLOR = 0xAA0088 # Purple
13+
TEXT_COLOR = 0xFFFF00
14+
15+
# Release any resources currently in use for the displays
16+
displayio.release_displays()
17+
18+
tft_cs = board.GP17
19+
tft_dc = board.GP16
20+
spi_mosi = board.GP19
21+
spi_clk = board.GP18
22+
spi = busio.SPI(spi_clk, spi_mosi)
23+
24+
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)
25+
display = ST7789(
26+
display_bus, rotation=270, width=240, height=135, rowstart=40, colstart=53
27+
)
28+
29+
# Make the display context
30+
splash = displayio.Group(max_size=10)
31+
display.show(splash)
32+
33+
color_bitmap = displayio.Bitmap(display.width, display.height, 1)
34+
color_palette = displayio.Palette(1)
35+
color_palette[0] = BACKGROUND_COLOR
36+
37+
bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
38+
splash.append(bg_sprite)
39+
40+
# Draw a smaller inner rectangle
41+
inner_bitmap = displayio.Bitmap(
42+
display.width - BORDER * 2, display.height - BORDER * 2, 1
43+
)
44+
inner_palette = displayio.Palette(1)
45+
inner_palette[0] = FOREGROUND_COLOR
46+
inner_sprite = displayio.TileGrid(
47+
inner_bitmap, pixel_shader=inner_palette, x=BORDER, y=BORDER
48+
)
49+
splash.append(inner_sprite)
50+
51+
# Draw a label
52+
text = "Hello World!"
53+
text_area = label.Label(terminalio.FONT, text=text, color=TEXT_COLOR)
54+
text_width = text_area.bounding_box[2] * FONTSCALE
55+
text_group = displayio.Group(
56+
max_size=10,
57+
scale=FONTSCALE,
58+
x=display.width // 2 - text_width // 2,
59+
y=display.height // 2,
60+
)
61+
text_group.append(text_area) # Subgroup for text scaling
62+
splash.append(text_group)
63+
64+
while True:
65+
pass

0 commit comments

Comments
 (0)