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