pimoroni-pico/micropython/modules/pico_scroll
Phil Howard 540bc2f75f Pico Unicorn/Scroll: Add buttons/dimensions to both module and class. 2023-03-27 15:11:30 +01:00
..
README.md Pico Scroll: Refactor to class. 2023-03-16 13:25:19 +00:00
bitmap.png Font bitmap 2021-04-17 15:49:28 +01:00
micropython.cmake Move scroll_text, show_text, bitmap_1d and set_pixels into C++ library 2021-04-22 20:00:25 +01:00
pico_scroll.c Pico Unicorn/Scroll: Add buttons/dimensions to both module and class. 2023-03-27 15:11:30 +01:00
pico_scroll.cpp Pico Scroll: Add support for PicoGraphics. 2023-03-16 16:59:31 +00:00
pico_scroll.h Pico Scroll: Add support for PicoGraphics. 2023-03-16 16:59:31 +00:00

README.md

Pico Scroll Pack - MicroPython

Our Pico Scroll Pack offers a 17x7 white LED matrix for your Raspberry Pi Pico. It also includes four buttons!

We've included helper functions to handle every aspect of drawing to the matrix and interfacing with the buttons. See the function reference for details.

Example Program

The following example sets up the matrix, sets each pixel to an increasing brightnesses level, and then clears the matrix only after button A is pressed.

from picoscroll import PicoScroll

# Initialise the board
picoscroll = PicoScroll()

brightness = 0

# For each pixel in the matrix
for y in range (0, picoscroll.get_height()):
  for x in range (0, picoscroll.get_width()):
    # Set that pixel to an increasing level of brightness
    picoscroll.set_pixel(x, y, brightness)
    brightness += 2

# Push the data to the matrix
picoscroll.update()

# Wait until the A button is pressed
while picoscroll.is_pressed(picoscroll.BUTTON_A) == False:
    pass

# Set the brightness of all pixels to 0
picoscroll.clear()
picoscroll.update()

Function reference

get_width

get_height

These return integers describing the height and width of the Scroll Pack in pixels.

width_in_pixels = picoscroll.get_width()
height_in_pixels = picoscroll.get_height()

set_pixel

This function sets a pixel at the x and y coordinates to a brightness level specified by the l parameter. The value of l must be 0-255. Changes will not be visible until update() is called.

picoscroll.set_pixel(x, y, l)

set_pixels

This function sets all pixel at once from a bytearray image indexed as y * picoscroll.get_width() + x, containing brightness levels between 0 and 255. Changes will not be visible until update() is called.

image = bytearray(0 for j in range(width * height))
picoscroll.set_pixels(image)

show_text

Show a text string with given brightness and offset - allowing you to scroll text across the display. Can also be passed a bytearray. Font is 5x7 pixels, with a 1 pixel space between characters, so to scroll a phrase across the entire display involves offsets from -17 pixels to 6 x len(str):

word = "Hello, world!"
l = len(word) * 6
for j in range(-17, l):
    picoscroll.show_text(word, 8, j)
    picoscroll.update()
    time.sleep(0.1)

The full 256 characters can be displayed with:

b = bytearray(range(256))
for j in range(256*6):
    picoscroll.show_text(b, 8, j)
    picoscroll.update()
    time.sleep(0.1)

Font map

scroll_text

Scroll a string across the picoscroll, starting off the right hand side, to the left, with a given delay in ms.

picoscroll.scroll_text("Hello, world!", 8, 100)

The full 256 characters can be displayed with:

b = bytearray(range(256))
picoscroll.scroll_text(b, 8, 100)

show_bitmap_1d

Show a view of a bitmap stored as the 7 least significant bits of bytes in a bytearray, top-down. Individual pixels are set to brightness based on individual bit values, with the view defined by the offset and the width of the scroll (i.e. 17 columns). Changes will not be visible until update() is called.

bitmap = bytearray(j for j in range 127)
for offset in range(-17, 127):
    picoscroll.show_bitmap_1d(bitmap, 16, offset)
    picoscroll.update()

will scroll a binary counter across the display (i.e. show 0x00 to 0x7f in binary).

update

Pushes pixel data from the Pico to the Scroll Pack. Until this function is called any set_pixel or clear calls won't have any visible effect.

picoscroll.update()

clear

Sets the brightness of all pixels to 0. Will not visibly take effect until update is called.

picoscroll.clear()

is_pressed

Checks if a specified button is currently being pressed. Valid values of b are picoscroll.BUTTON_A, picoscroll.BUTTON_B, picoscroll.BUTTON_X, or picoscroll.BUTTON_Y, which match the silkscreen labels beside the buttons on the board.

picoscroll.is_pressed(b)