Skip to content

Commit b827dc2

Browse files
authored
Update st7789_280x240_simpletest.py
#Issue Add an extended version of st7789_280x240_simpletest.py adafruit#42 #Pull Request Enhanced compatibility adafruit#40
1 parent 43a67c2 commit b827dc2

File tree

1 file changed

+33
-13
lines changed

1 file changed

+33
-13
lines changed

examples/st7789_280x240_simpletest.py

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,69 @@
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
1011
import displayio
1112
import terminalio
1213
from adafruit_display_text import label
1314
from fourwire import FourWire
14-
1515
from adafruit_st7789 import ST7789
1616

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

26-
display = ST7789(display_bus, width=280, height=240, rowstart=20, rotation=90)
44+
# set the backlight
45+
# minimum value 0.001 (0.000 would be off), maximum value 1.000
46+
display.brightness = 0.5
2747

2848
# Make the display context
2949
splash = displayio.Group()
3050
display.root_group = splash
3151

32-
color_bitmap = displayio.Bitmap(280, 240, 1)
52+
# Draw background rectangle
53+
color_bitmap = displayio.Bitmap(color_bitmap_x, color_bitmap_y, 1)
3354
color_palette = displayio.Palette(1)
3455
color_palette[0] = 0x00FF00 # Bright Green
35-
3656
bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
3757
splash.append(bg_sprite)
3858

3959
# Draw a smaller inner rectangle
40-
inner_bitmap = displayio.Bitmap(240, 200, 1)
60+
inner_bitmap = displayio.Bitmap(inner_bitmap_x, inner_bitmap_y, 1)
4161
inner_palette = displayio.Palette(1)
4262
inner_palette[0] = 0xAA0088 # Purple
4363
inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=20, y=20)
4464
splash.append(inner_sprite)
4565

4666
# Draw a label
47-
text_group = displayio.Group(scale=3, x=37, y=120)
67+
text_group = displayio.Group(scale=scale, x=x, y=y)
4868
text = "Hello World!"
4969
text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00)
5070
text_group.append(text_area) # Subgroup for text scaling

0 commit comments

Comments
 (0)