|
| 1 | +# This example shows how to use text and graphics to create custom signage |
| 2 | + |
| 3 | +import time |
| 4 | +import adafruit_display_text.label |
| 5 | +import board |
| 6 | +import displayio |
| 7 | +import framebufferio |
| 8 | +import rgbmatrix |
| 9 | +import terminalio |
| 10 | + |
| 11 | +# If there was a display before (protomatter, LCD, or E-paper), release it so |
| 12 | +# we can create ours |
| 13 | +displayio.release_displays() |
| 14 | + |
| 15 | +matrix = rgbmatrix.RGBMatrix( |
| 16 | + width=64, bit_depth=4, |
| 17 | + rgb_pins=[board.MTX_R1, board.MTX_G1, board.MTX_B1, board.MTX_R2, board.MTX_G2, board.MTX_B2], |
| 18 | + addr_pins=[board.MTX_ADDRA, board.MTX_ADDRB, board.MTX_ADDRC, board.MTX_ADDRD], |
| 19 | + clock_pin=board.MTX_CLK, latch_pin=board.MTX_LAT, output_enable_pin=board.MTX_OE) |
| 20 | + |
| 21 | +# Associate the RGB matrix with a Display so that we can use displayio features |
| 22 | +display = framebufferio.FramebufferDisplay(matrix, auto_refresh=False) |
| 23 | +display.rotation = 180 |
| 24 | + |
| 25 | +R = adafruit_display_text.label.Label( |
| 26 | + terminalio.FONT, |
| 27 | + color=0xff0000, |
| 28 | + scale=3, x=2, y=13, |
| 29 | + text="R") |
| 30 | +B = adafruit_display_text.label.Label( |
| 31 | + terminalio.FONT, |
| 32 | + color=0x0000ff, |
| 33 | + scale=3, x=24, y=13, |
| 34 | + text="B") |
| 35 | +G = adafruit_display_text.label.Label( |
| 36 | + terminalio.FONT, |
| 37 | + color=0x00ff00, |
| 38 | + scale=3, x=46, y=13, |
| 39 | + text="G") |
| 40 | + |
| 41 | +# Put each line of text into a Group, then show that group. |
| 42 | +g = displayio.Group() |
| 43 | +g.append(R) |
| 44 | +g.append(B) |
| 45 | +g.append(G) |
| 46 | +display.show(g) |
| 47 | +display.auto_refresh = True |
| 48 | + |
| 49 | +bitmap_file = open("/rbg.bmp", "rb") |
| 50 | +# Setup the file as the bitmap data source |
| 51 | +bitmap = displayio.OnDiskBitmap(bitmap_file) |
| 52 | +# Create a TileGrid to hold the bitmap |
| 53 | +tile_grid = displayio.TileGrid(bitmap, pixel_shader=displayio.ColorConverter()) |
| 54 | +print(dir(tile_grid)) |
| 55 | + |
| 56 | +while True: |
| 57 | + while g: |
| 58 | + g.pop() |
| 59 | + |
| 60 | + g.append(tile_grid) |
| 61 | + for y in range(bitmap.height+32): |
| 62 | + tile_grid.y = 32-y |
| 63 | + time.sleep(0.05) |
| 64 | + |
| 65 | + g.pop() |
| 66 | + |
| 67 | + g.append(R) |
| 68 | + time.sleep(1) |
| 69 | + g.append(B) |
| 70 | + time.sleep(1) |
| 71 | + g.append(G) |
| 72 | + time.sleep(1) |
0 commit comments