Graeme Winter

Numbers on picoscroll

TL;DR

Display numbers on scroll? 👇

Code here

verbose=true

One of the first things you may want to do with your new pico / scroll could be to display numbers and text… unfortunately as the pi pico only came out a few weeks back, the tops are even newer so the library / API support is … rudimentary. This is not a problem, it is an opportunity…

Usual imports:

import time

import picoscroll as scroll

Useful code:

# constants - layout of numbers - all are in a 4x5 box so can encode as
# to binary byte strings

__NUMBERS = (
    "01101011110110010110",
    "00100110001000100010",
    "01101001001001001111",
    "11100001001000011110",
    "10011001111100010001",
    "11111000111000011110",
    "01101000111010010110",
    "11110001001000100010",
    "01101001011010010110",
    "01101001011100010110",
)

This first block is a set of poorly encoded bitmaps for digits - essentially looping over a 5x4 array (slow / y, fast/ x) will give you a digit. Then usual init code:

scroll.init()
width = scroll.get_width()
height = scroll.get_height()

Code to (i) plot digit at a place, (ii) write a number (N.B. only room for 3 digits…):

def plot_digit(digit, x, y, b):
    """Write the digit at the offset starting at x, y with brightness b"""

    code = __NUMBERS[digit]

    assert x >= 0
    assert x + 4 < width
    assert y >= 0
    assert y + 5 < height

    for _y in range(5):
        for _x in range(4):
            if code[_x + 4 * _y] == "1":
                scroll.set_pixel(_x + x, _y + y, b)
            else:
                scroll.set_pixel(_x + x, _y + y, 0)


def plot_number(value):
    assert value < 1000
    digits = map(int, reversed(str(value)))
    scroll.clear()
    for j, digit in enumerate(digits):
        plot_digit(digit, width - 5 * (j + 1), 1, 64)
    scroll.update()

t0 = time.time()

while True: t = int(time.time() - t0) plot_number(t) time.sleep(0.2) ```

Driver at the end is a dumb demo - I should really move this to a library…