|
1 |
| -import time |
| 1 | +""" |
| 2 | +This test will initialize the display using displayio and draw a solid white |
| 3 | +background, a smaller black rectangle, and some white text. |
| 4 | +""" |
| 5 | + |
2 | 6 | import board
|
3 |
| -import busio |
4 | 7 | import displayio
|
| 8 | +import terminalio |
| 9 | +from adafruit_display_text import label |
5 | 10 | import adafruit_ssd1325
|
6 | 11 |
|
7 | 12 | displayio.release_displays()
|
8 | 13 |
|
9 |
| -# This pinout works on a Metro and may need to be altered for other boards. |
10 |
| -spi = busio.SPI(board.SCL, board.SDA) |
11 |
| -tft_cs = board.D9 |
12 |
| -tft_dc = board.D8 |
13 |
| -tft_reset = board.D7 |
| 14 | +# Use for SPI |
| 15 | +spi = board.SPI() |
| 16 | +oled_cs = board.D5 |
| 17 | +oled_dc = board.D6 |
| 18 | +display_bus = displayio.FourWire(spi, command=oled_dc, chip_select=oled_cs, |
| 19 | + baudrate=1000000, reset=board.D9) |
| 20 | + |
| 21 | +# Use for I2C |
| 22 | +# i2c = board.I2C() |
| 23 | +# display_bus = displayio.I2CDisplay(i2c, device_address=0x3c) |
| 24 | + |
| 25 | +WIDTH = 128 |
| 26 | +HEIGHT = 64 |
| 27 | +BORDER = 8 |
| 28 | +FONTSCALE = 1 |
| 29 | + |
| 30 | +display = adafruit_ssd1325.SSD1325(display_bus, width=WIDTH, height=HEIGHT) |
| 31 | + |
| 32 | +# Make the display context |
| 33 | +splash = displayio.Group(max_size=10) |
| 34 | +display.show(splash) |
| 35 | + |
| 36 | +color_bitmap = displayio.Bitmap(display.width, display.height, 1) |
| 37 | +color_palette = displayio.Palette(1) |
| 38 | +color_palette[0] = 0x888888 # White |
| 39 | + |
| 40 | +bg_sprite = displayio.TileGrid(color_bitmap, |
| 41 | + pixel_shader=color_palette, |
| 42 | + x=0, y=0) |
| 43 | +splash.append(bg_sprite) |
| 44 | + |
| 45 | +# Draw a smaller inner rectangle |
| 46 | +inner_bitmap = displayio.Bitmap(display.width - BORDER * 2, display.height - BORDER * 2, 1) |
| 47 | +inner_palette = displayio.Palette(1) |
| 48 | +inner_palette[0] = 0x000000 # Black |
| 49 | +inner_sprite = displayio.TileGrid(inner_bitmap, |
| 50 | + pixel_shader=inner_palette, |
| 51 | + x=BORDER, y=BORDER) |
| 52 | +splash.append(inner_sprite) |
| 53 | + |
| 54 | +# Draw a label |
| 55 | +text = "Hello World!" |
| 56 | +text_area = label.Label(terminalio.FONT, text=text, color=0xFFFFFF) |
| 57 | +text_width = text_area.bounding_box[2] * FONTSCALE |
| 58 | +text_group = displayio.Group(max_size=10, scale=FONTSCALE, x=display.width // 2 - text_width // 2, |
| 59 | + y=display.height // 2) |
| 60 | +text_group.append(text_area) # Subgroup for text scaling |
| 61 | +splash.append(text_group) |
14 | 62 |
|
15 |
| -display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=tft_reset, |
16 |
| - baudrate=1000000) |
17 |
| -time.sleep(1) |
18 |
| -display = adafruit_ssd1325.SSD1325(display_bus, width=128, height=64) |
| 63 | +while True: |
| 64 | + pass |
0 commit comments