ssd1325_simpletest.py
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 6 import board 7 import displayio 8 import terminalio 9 from adafruit_display_text import label 10 import adafruit_ssd1325 11 12 displayio.release_displays() 13 14 # Use for SPI 15 spi = board.SPI() 16 oled_cs = board.D5 17 oled_dc = board.D6 18 display_bus = displayio.FourWire( 19 spi, command=oled_dc, chip_select=oled_cs, baudrate=1000000, reset=board.D9 20 ) 21 22 # Use for I2C 23 # i2c = board.I2C() 24 # display_bus = displayio.I2CDisplay(i2c, device_address=0x3c) 25 26 WIDTH = 128 27 HEIGHT = 64 28 BORDER = 8 29 FONTSCALE = 1 30 31 display = adafruit_ssd1325.SSD1325(display_bus, width=WIDTH, height=HEIGHT) 32 33 # Make the display context 34 splash = displayio.Group(max_size=10) 35 display.show(splash) 36 37 color_bitmap = displayio.Bitmap(display.width, display.height, 1) 38 color_palette = displayio.Palette(1) 39 color_palette[0] = 0xFFFFFF # White 40 41 bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0) 42 splash.append(bg_sprite) 43 44 # Draw a smaller inner rectangle 45 inner_bitmap = displayio.Bitmap( 46 display.width - BORDER * 2, display.height - BORDER * 2, 1 47 ) 48 inner_palette = displayio.Palette(1) 49 inner_palette[0] = 0x000000 # Black 50 inner_sprite = displayio.TileGrid( 51 inner_bitmap, pixel_shader=inner_palette, x=BORDER, y=BORDER 52 ) 53 splash.append(inner_sprite) 54 55 # Draw a label 56 text = "Hello World!" 57 text_area = label.Label(terminalio.FONT, text=text, color=0x888888) 58 text_width = text_area.bounding_box[2] * FONTSCALE 59 text_group = displayio.Group( 60 max_size=10, 61 scale=FONTSCALE, 62 x=display.width // 2 - text_width // 2, 63 y=display.height // 2, 64 ) 65 text_group.append(text_area) # Subgroup for text scaling 66 splash.append(text_group) 67 68 while True: 69 pass