|
2 | 2 | # SPDX-License-Identifier: MIT
|
3 | 3 |
|
4 | 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. |
| 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. |
7 | 8 | """
|
8 | 9 |
|
9 | 10 | import board
|
10 | 11 | import displayio
|
11 | 12 | import terminalio
|
12 | 13 | from adafruit_display_text import label
|
13 | 14 | from fourwire import FourWire
|
14 |
| - |
15 | 15 | from adafruit_st7789 import ST7789
|
16 | 16 |
|
| 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 | + |
17 | 35 | # Release any resources currently in use for the displays
|
18 | 36 | displayio.release_displays()
|
19 |
| - |
20 | 37 | 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) |
25 | 43 |
|
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 |
27 | 47 |
|
28 | 48 | # Make the display context
|
29 | 49 | splash = displayio.Group()
|
30 | 50 | display.root_group = splash
|
31 | 51 |
|
32 |
| -color_bitmap = displayio.Bitmap(280, 240, 1) |
| 52 | +# Draw background rectangle |
| 53 | +color_bitmap = displayio.Bitmap(color_bitmap_x, color_bitmap_y, 1) |
33 | 54 | color_palette = displayio.Palette(1)
|
34 | 55 | color_palette[0] = 0x00FF00 # Bright Green
|
35 |
| - |
36 | 56 | bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
|
37 | 57 | splash.append(bg_sprite)
|
38 | 58 |
|
39 | 59 | # 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) |
41 | 61 | inner_palette = displayio.Palette(1)
|
42 | 62 | inner_palette[0] = 0xAA0088 # Purple
|
43 | 63 | inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=20, y=20)
|
44 | 64 | splash.append(inner_sprite)
|
45 | 65 |
|
46 | 66 | # 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) |
48 | 68 | text = "Hello World!"
|
49 | 69 | text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00)
|
50 | 70 | text_group.append(text_area) # Subgroup for text scaling
|
|
0 commit comments