Skip to content

Commit 59bbfc2

Browse files
committed
Add examples for 1.47 and 1.9 displays
1 parent 79c70a4 commit 59bbfc2

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
"""
5+
This test will initialize the display using displayio and draw a solid green
6+
background, a smaller purple rectangle, and some yellow text.
7+
"""
8+
import board
9+
import terminalio
10+
import displayio
11+
from adafruit_display_text import label
12+
from adafruit_st7789 import ST7789
13+
14+
BORDER_WIDTH = 20
15+
TEXT_SCALE = 3
16+
17+
# Release any resources currently in use for the displays
18+
displayio.release_displays()
19+
20+
spi = board.SPI()
21+
tft_cs = board.D5
22+
tft_dc = board.D6
23+
tft_rst = board.D9
24+
25+
display_bus = displayio.FourWire(
26+
spi, command=tft_dc, chip_select=tft_cs, reset=tft_rst
27+
)
28+
29+
display = ST7789(display_bus, width=320, height=170, colstart=34, rotation=90)
30+
31+
# Make the display context
32+
splash = displayio.Group()
33+
display.show(splash)
34+
35+
color_bitmap = displayio.Bitmap(display.width, display.height, 1)
36+
color_palette = displayio.Palette(1)
37+
color_palette[0] = 0x00FF00 # Bright Green
38+
bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
39+
splash.append(bg_sprite)
40+
41+
# Draw a smaller inner rectangle
42+
inner_bitmap = displayio.Bitmap(display.width - (BORDER_WIDTH * 2), display.height - (BORDER_WIDTH * 2), 1)
43+
inner_palette = displayio.Palette(1)
44+
inner_palette[0] = 0xAA0088 # Purple
45+
inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=BORDER_WIDTH, y=BORDER_WIDTH)
46+
splash.append(inner_sprite)
47+
48+
# Draw a label
49+
text_area = label.Label(
50+
terminalio.FONT,
51+
text="Hello World!",
52+
color=0xFFFF00,
53+
scale=TEXT_SCALE,
54+
anchor_point=(0.5, 0.5),
55+
anchored_position=(display.width // 2, display.height // 2)
56+
)
57+
splash.append(text_area)
58+
59+
while True:
60+
pass
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
"""
5+
This test will initialize the display using displayio and draw a solid green
6+
background, a smaller purple rectangle, and some yellow text.
7+
"""
8+
import board
9+
import terminalio
10+
import displayio
11+
from adafruit_display_text import label
12+
from adafruit_st7789 import ST7789
13+
14+
BORDER_WIDTH = 20
15+
TEXT_SCALE = 3
16+
17+
# Release any resources currently in use for the displays
18+
displayio.release_displays()
19+
20+
spi = board.SPI()
21+
tft_cs = board.D5
22+
tft_dc = board.D6
23+
tft_rst = board.D9
24+
25+
display_bus = displayio.FourWire(
26+
spi, command=tft_dc, chip_select=tft_cs, reset=tft_rst
27+
)
28+
29+
display = ST7789(display_bus, width=320, height=172, colstart=34, rotation=270)
30+
31+
# Make the display context
32+
splash = displayio.Group()
33+
display.show(splash)
34+
35+
color_bitmap = displayio.Bitmap(display.width, display.height, 1)
36+
color_palette = displayio.Palette(1)
37+
color_palette[0] = 0x00FF00 # Bright Green
38+
bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
39+
splash.append(bg_sprite)
40+
41+
# Draw a smaller inner rectangle
42+
inner_bitmap = displayio.Bitmap(display.width - (BORDER_WIDTH * 2), display.height - (BORDER_WIDTH * 2), 1)
43+
inner_palette = displayio.Palette(1)
44+
inner_palette[0] = 0xAA0088 # Purple
45+
inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=BORDER_WIDTH, y=BORDER_WIDTH)
46+
splash.append(inner_sprite)
47+
48+
# Draw a label
49+
text_area = label.Label(
50+
terminalio.FONT,
51+
text="Hello World!",
52+
color=0xFFFF00,
53+
scale=TEXT_SCALE,
54+
anchor_point=(0.5, 0.5),
55+
anchored_position=(display.width // 2, display.height // 2)
56+
)
57+
splash.append(text_area)
58+
59+
while True:
60+
pass

0 commit comments

Comments
 (0)