Now that we can shift in arbitrary bit patterns, we can get more elaborate. This example will use the shift_in_string(font, s, color, delay)
function to scroll text onto the pixel array. font
is the font to use for character images, s
is the string to be displayed, color
is the color to use, and delay
is the time to wait in seconds between columns.
import board import dotstar_featherwing import time import font3 wing = dotstar_featherwing.DotstarFeatherwing(board.D13, board.D11, 0.1) while True: wing.clear() wing.shift_in_string(font3.font, "hello adafruit discord!", (32, 32, 32), 0.05) time.sleep(2)
Even a font of character 3 pixels wide takes up some space in memory. That last demo pretty much fills the Feather-M0s RAM. If you have a specific message or messages to scroll, consider removing any character from the font that you don’t need.
Another neat capability of the library is that characters (glyphs really) don’t have to all be the same width. This lets you have some custom images stored in a font to be displayed as and when you wish.
Fonts
A font is simply a dictionary that maps characters to their bitmap. This bitmap is a list of integers that define each vertical stripe of the character image. The first stripe is the left-most (and will get shifted onto the display first, from the right) and the lowest bit of each stripe is at the top.
Here's font3
:
font = {' ': [ 0, 0, 0], 'A': [62, 5, 62], 'B': [63, 37, 26], 'C': [30, 33, 18], 'D': [63, 33, 30], 'E': [63, 37, 33], 'F': [63, 5, 1], 'G': [30, 41, 26], 'H': [63, 4, 63], 'I': [33, 63, 33], 'J': [33, 31, 1], 'K': [63, 4, 59], 'L': [63, 32, 32], 'M': [63, 2, 63], 'N': [63, 12, 63], 'O': [30, 33, 30], 'P': [63, 5, 2], 'Q': [30, 33, 62], 'R': [63, 5, 58], 'S': [18, 37, 26], 'T': [ 1, 63, 1], 'U': [31, 32, 63], 'V': [31, 32, 31], 'W': [63, 16, 63], 'X': [59, 4, 59], 'Y': [ 3, 60, 3], 'Z': [49, 45, 35], '0': [30, 33, 30], '1': [34, 63, 32], '2': [50, 41, 38], '3': [33, 37, 26], '4': [ 7, 4, 63], '5': [23, 37, 25], '6': [30, 41, 25], '7': [49, 9, 7], '8': [26, 37, 26], '9': [38, 41, 30], '!': [ 0, 47, 0], '?': [ 2, 41, 6], '.': [ 0, 32, 0], '-': [ 8, 8, 8], '_': [32, 32, 32], '+': [ 8, 28, 8], '/': [48, 12, 3], '*': [20, 8, 20], '=': [20, 20, 20], 'UNKNOWN': [63, 33, 63] }
The UNKNOWN
entry is used internally when a character not specified in the dictionary is encountered.
Text editor powered by tinymce.