|
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
|
|
14 | 15 |
|
15 | 16 | from adafruit_st7789 import ST7789
|
16 | 17 |
|
| 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 | + |
17 | 36 | # Release any resources currently in use for the displays
|
18 | 37 | displayio.release_displays()
|
19 |
| - |
20 | 38 | 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 | +) |
23 | 54 |
|
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 |
27 | 58 |
|
28 | 59 | # Make the display context
|
29 | 60 | splash = displayio.Group()
|
30 | 61 | display.root_group = splash
|
31 | 62 |
|
32 |
| -color_bitmap = displayio.Bitmap(280, 240, 1) |
| 63 | +# Draw background rectangle |
| 64 | +color_bitmap = displayio.Bitmap(color_bitmap_x, color_bitmap_y, 1) |
33 | 65 | color_palette = displayio.Palette(1)
|
34 | 66 | color_palette[0] = 0x00FF00 # Bright Green
|
35 |
| - |
36 | 67 | bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
|
37 | 68 | splash.append(bg_sprite)
|
38 | 69 |
|
39 | 70 | # 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) |
41 | 72 | inner_palette = displayio.Palette(1)
|
42 | 73 | inner_palette[0] = 0xAA0088 # Purple
|
43 | 74 | inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=20, y=20)
|
44 | 75 | splash.append(inner_sprite)
|
45 | 76 |
|
46 | 77 | # 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) |
48 | 79 | text = "Hello World!"
|
49 | 80 | text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00)
|
50 | 81 | text_group.append(text_area) # Subgroup for text scaling
|
|
0 commit comments