Skip to content

Commit 46cf5ed

Browse files
authored
Merge pull request #21 from wildestpixel/patch-1
Create st7789_240x135_simpletest_Pimoroni_Pico_Display_Pack.py
2 parents ee92f2f + ae0afaf commit 46cf5ed

File tree

1 file changed

+68
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)