|
1 |
| -import time |
2 | 1 | import board
|
3 |
| -import busio |
4 | 2 | import displayio
|
| 3 | +import terminalio |
| 4 | +from adafruit_display_text import label |
5 | 5 | import adafruit_ssd1327
|
6 | 6 |
|
7 | 7 | displayio.release_displays()
|
8 | 8 |
|
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.D6 |
12 |
| -tft_dc = board.D9 |
13 |
| -tft_reset = board.D5 |
| 9 | +# Use for I2C |
| 10 | +i2c = board.I2C() |
| 11 | +display_bus = displayio.I2CDisplay(i2c, device_address=0x3D) |
14 | 12 |
|
15 |
| -display_bus = displayio.FourWire( |
16 |
| - spi, command=tft_dc, chip_select=tft_cs, reset=tft_reset, baudrate=1000000 |
| 13 | +# Use for SPI |
| 14 | +# spi = board.SPI() |
| 15 | +# oled_cs = board.D5 |
| 16 | +# oled_dc = board.D6 |
| 17 | +# display_bus = displayio.FourWire( |
| 18 | +# spi, command=oled_dc, chip_select=oled_cs, baudrate=1000000, reset=board.D9 |
| 19 | +# ) |
| 20 | + |
| 21 | +WIDTH = 128 |
| 22 | +HEIGHT = 128 |
| 23 | +BORDER = 8 |
| 24 | +FONTSCALE = 1 |
| 25 | + |
| 26 | +display = adafruit_ssd1327.SSD1327(display_bus, width=WIDTH, height=HEIGHT) |
| 27 | + |
| 28 | +# Make the display context |
| 29 | +splash = displayio.Group(max_size=10) |
| 30 | +display.show(splash) |
| 31 | + |
| 32 | +# Draw a background rectangle, but not the full display size |
| 33 | +color_bitmap = displayio.Bitmap( |
| 34 | + display.width - BORDER * 2, display.height - BORDER * 2, 1 |
| 35 | +) |
| 36 | +color_palette = displayio.Palette(1) |
| 37 | +color_palette[0] = 0xFFFFFF # White |
| 38 | +bg_sprite = displayio.TileGrid( |
| 39 | + color_bitmap, pixel_shader=color_palette, x=BORDER, y=BORDER |
17 | 40 | )
|
18 |
| -time.sleep(1) |
19 |
| -display = adafruit_ssd1327.SSD1327(display_bus, width=128, height=128) |
| 41 | +splash.append(bg_sprite) |
| 42 | + |
| 43 | +# Draw a smaller inner rectangle |
| 44 | +inner_bitmap = displayio.Bitmap( |
| 45 | + display.width - BORDER * 4, display.height - BORDER * 4, 1 |
| 46 | +) |
| 47 | +inner_palette = displayio.Palette(1) |
| 48 | +inner_palette[0] = 0x888888 # Gray |
| 49 | +inner_sprite = displayio.TileGrid( |
| 50 | + inner_bitmap, pixel_shader=inner_palette, x=BORDER * 2, y=BORDER * 2 |
| 51 | +) |
| 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( |
| 59 | + max_size=10, |
| 60 | + scale=FONTSCALE, |
| 61 | + x=display.width // 2 - text_width // 2, |
| 62 | + y=display.height // 2, |
| 63 | +) |
| 64 | +text_group.append(text_area) # Subgroup for text scaling |
| 65 | +splash.append(text_group) |
| 66 | + |
| 67 | +while True: |
| 68 | + pass |
0 commit comments