Skip to content

Commit 5661a1c

Browse files
authored
Merge pull request #43 from CrackXT/main
Update st7789_280x240_simpletest.py
2 parents 43a67c2 + d40d752 commit 5661a1c

File tree

1 file changed

+43
-12
lines changed

1 file changed

+43
-12
lines changed

examples/st7789_280x240_simpletest.py

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
# SPDX-License-Identifier: MIT
33

44
"""
5-
This test will initialize the display using displayio and draw a solid green
6-
background, a smaller purple rectangle, and some yellow text.
5+
This test will initialize the display using displayio, set display brightness and draw a solid green
6+
background, a smaller purple rectangle, and some yellow text. The test also has the option of
7+
rotating the screen content.
78
"""
89

910
import board
@@ -14,37 +15,67 @@
1415

1516
from adafruit_st7789 import ST7789
1617

18+
# set the display rotation
19+
rotation = 90
20+
if rotation not in {0, 90, 180, 270}:
21+
raise ValueError("The value of rotation must be one of: 0, 90, 180, 270")
22+
23+
# Display settings depending on the selected rotation
24+
# first value default setting for 1.69" with 0° and 180° rotation
25+
# second value default setting for 1.69" with 90° and 270° rotation
26+
width = 240 if rotation in {0, 180} else 280
27+
height = 280 if rotation in {0, 180} else 240
28+
color_bitmap_x = 240 if rotation in {0, 180} else 280
29+
color_bitmap_y = 280 if rotation in {0, 180} else 240
30+
inner_bitmap_x = 200 if rotation in {0, 180} else 240
31+
inner_bitmap_y = 240 if rotation in {0, 180} else 200
32+
scale = 2 if rotation in {0, 180} else 3
33+
x = 50 if rotation in {0, 180} else 37
34+
y = 140 if rotation in {0, 180} else 120
35+
1736
# Release any resources currently in use for the displays
1837
displayio.release_displays()
19-
2038
spi = board.SPI()
21-
tft_cs = board.D5
22-
tft_dc = board.D6
39+
tft_cs = board.D20
40+
tft_dc = board.D21
41+
backlight = board.D6
42+
display_bus = FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D5)
43+
display = ST7789(
44+
display_bus,
45+
width=width,
46+
height=height,
47+
colstart=0,
48+
rowstart=20,
49+
rotation=rotation,
50+
backlight_pin=backlight,
51+
bgr=True,
52+
invert=True,
53+
)
2354

24-
display_bus = FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9)
25-
26-
display = ST7789(display_bus, width=280, height=240, rowstart=20, rotation=90)
55+
# set the backlight
56+
# minimum value 0.001 (0.000 would be off), maximum value 1.000
57+
display.brightness = 0.5
2758

2859
# Make the display context
2960
splash = displayio.Group()
3061
display.root_group = splash
3162

32-
color_bitmap = displayio.Bitmap(280, 240, 1)
63+
# Draw background rectangle
64+
color_bitmap = displayio.Bitmap(color_bitmap_x, color_bitmap_y, 1)
3365
color_palette = displayio.Palette(1)
3466
color_palette[0] = 0x00FF00 # Bright Green
35-
3667
bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
3768
splash.append(bg_sprite)
3869

3970
# Draw a smaller inner rectangle
40-
inner_bitmap = displayio.Bitmap(240, 200, 1)
71+
inner_bitmap = displayio.Bitmap(inner_bitmap_x, inner_bitmap_y, 1)
4172
inner_palette = displayio.Palette(1)
4273
inner_palette[0] = 0xAA0088 # Purple
4374
inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=20, y=20)
4475
splash.append(inner_sprite)
4576

4677
# Draw a label
47-
text_group = displayio.Group(scale=3, x=37, y=120)
78+
text_group = displayio.Group(scale=scale, x=x, y=y)
4879
text = "Hello World!"
4980
text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00)
5081
text_group.append(text_area) # Subgroup for text scaling

0 commit comments

Comments
 (0)