code.py
 1  # SPDX-FileCopyrightText: 2020 Jeff Epler for Adafruit Industries
 2  #
 3  # SPDX-License-Identifier: MIT
 4  
 5  # This example implements a simple two line scroller using
 6  # Adafruit_CircuitPython_Display_Text. Each line has its own color
 7  # and it is possible to modify the example to use other fonts and non-standard
 8  # characters.
 9  
10  import adafruit_display_text.label
11  import board
12  import displayio
13  import framebufferio
14  import rgbmatrix
15  import terminalio
16  
17  # If there was a display before (protomatter, LCD, or E-paper), release it so
18  # we can create ours
19  displayio.release_displays()
20  
21  # This next call creates the RGB Matrix object itself. It has the given width
22  # and height. bit_depth can range from 1 to 6; higher numbers allow more color
23  # shades to be displayed, but increase memory usage and slow down your Python
24  # code. If you just want to show primary colors plus black and white, use 1.
25  # Otherwise, try 3, 4 and 5 to see which effect you like best.
26  #
27  # These lines are for the Feather M4 Express. If you're using a different board,
28  # check the guide to find the pins and wiring diagrams for your board.
29  # If you have a matrix with a different width or height, change that too.
30  # If you have a 16x32 display, try with just a single line of text.
31  matrix = rgbmatrix.RGBMatrix(
32      width=64, height=32, bit_depth=1,
33      rgb_pins=[board.D6, board.D5, board.D9, board.D11, board.D10, board.D12],
34      addr_pins=[board.A5, board.A4, board.A3, board.A2],
35      clock_pin=board.D13, latch_pin=board.D0, output_enable_pin=board.D1)
36  
37  # Associate the RGB matrix with a Display so that we can use displayio features
38  display = framebufferio.FramebufferDisplay(matrix, auto_refresh=False)
39  
40  # Create two lines of text to scroll. Besides changing the text, you can also
41  # customize the color and font (using Adafruit_CircuitPython_Bitmap_Font).
42  # To keep this demo simple, we just used the built-in font.
43  # The Y coordinates of the two lines were chosen so that they looked good
44  # but if you change the font you might find that other values work better.
45  line1 = adafruit_display_text.label.Label(
46      terminalio.FONT,
47      color=0xff0000,
48      text="This scroller is brought to you by CircuitPython RGBMatrix")
49  line1.x = display.width
50  line1.y = 8
51  
52  line2 = adafruit_display_text.label.Label(
53      terminalio.FONT,
54      color=0x0080ff,
55      text="Hello to all CircuitPython contributors worldwide <3")
56  line2.x = display.width
57  line2.y = 24
58  
59  # Put each line of text into a Group, then show that group.
60  g = displayio.Group()
61  g.append(line1)
62  g.append(line2)
63  display.show(g)
64  
65  # This function will scoot one label a pixel to the left and send it back to
66  # the far right if it's gone all the way off screen. This goes in a function
67  # because we'll do exactly the same thing with line1 and line2 below.
68  def scroll(line):
69      line.x = line.x - 1
70      line_width = line.bounding_box[2]
71      if line.x < -line_width:
72          line.x = display.width
73  
74  # This function scrolls lines backwards.  Try switching which function is
75  # called for line2 below!
76  def reverse_scroll(line):
77      line.x = line.x + 1
78      line_width = line.bounding_box[2]
79      if line.x >= display.width:
80          line.x = -line_width
81  
82  # You can add more effects in this loop. For instance, maybe you want to set the
83  # color of each label to a different value.
84  while True:
85      scroll(line1)
86      scroll(line2)
87      #reverse_scroll(line2)
88      display.refresh(minimum_frames_per_second=0)