Images

Monochromatic Images

Displaying a single color (and “black”) image is straight-forward. It uses a list of strings to encode which pixels are colored and which are off. Uppercase X is used to indicate a lit pixel, any other character indicates an unlit pixel. I’ve found a period to work well visually.

The display_image(image, color) function has two parameters: the bitmap and the color to use for "on" pixels. Each line of the bitmap corresponds to a 12 pixel row of the display. Since the display is 6 pixels tall, the bitmap will have 6 such rows.

import board
import dotstar_featherwing

wing = dotstar_featherwing.DotstarFeatherwing(board.D13, board.D11)

starfleet = ["XXXXXXX.....",
             "..XXXXXXX...",
             "....XXXXXXX.",
             ".....XXXXXXX",
             "....XXXXXXX.",
             "..XXXXXXX..."]

wing.display_image(starfleet, (32, 32, 32))

Multi-coloured images

Using a dictionary to map characters in the bitmap strings to colors, a color image can be displayed.

The display_colored_image(image, colors) functions takes an image as before, but its second parameter is a color mapping dictionary rather than a single color.

import board
import dotstar_featherwing

wing = dotstar_featherwing.DotstarFeatherwing(board.D13, board.D11)

xmas = ["..y.w......w",
        "..G.....w...",
        "..G..w....w.",
        ".GGG...w....",
        "GGGGG.......",
        "wwwwwwwwwwww"]

xmas_colors = {'w': ( 32,  32,  32),
               'G': (  0,  32,   0),
               'y': ( 32,  32,   0)}

wing.display_colored_image(xmas, xmas_colors)

A snowy winter scene.

Animation

To go from displaying a static colored image to an animated one is just a matter of displaying a series of images in sequence.

The display_animation(animation, colors, count, delay) function does just that. The animation parameter is a list of images (each a list of strings as before). These are the frames in the animation. colors is the color mapping, again as before. count is the number of times to run the animation, which defaults to 1. Finally, delay is the time in seconds to wait between frames (including the final frame of a sequence and the first frame of the next repetition), and defaults to 0.1 seconds.

import board
import dotstar_featherwing

wing = dotstar_featherwing.DotstarFeatherwing(board.D13, board.D11)

xmas_colors = {'w': ( 32,  32,  32),
               'W': (255, 255, 255),
               'G': (  0,  32,   0),
               'y': ( 32,  32,   0),
               'Y': (255, 255,   0)}

xmas_animation = [["..y.w......w",
                   "..G.....w...",
                   "..G..w....w.",
                   ".GGG...w....",
                   "GGGGG.......",
                   "wwwwwwwwwwww"],
                  ["..y.........",
                   "..G.W......w",
                   "..G.....w...",
                   ".GGG.w....W.",
                   "GGGGG..w....",
                   "wwwwwwwwwwww"],
                  ["..Y....W....",
                   "..G.........",
                   "..G.w......w",
                   ".GGG....w...",
                   "GGGGGw....W.",
                   "wwwwwwwwwwww"],
                  ["..y..w....w.",
                   "..G....W....",
                   "..G.........",
                   ".GGGW......w",
                   "GGGGG...w...",
                   "wwwwwwwwwwww"],
                  ["..Y.....w...",
                   "..G..w....W.",
                   "..G....w....",
                   ".GGG........",
                   "GGGGG......W",
                   "wwwwwwwwwwww"]]

wing.display_animation(xmas_animation, xmas_colors, 10, 0.05)

By using brighter versions of a couple colors, we can make the snow glitter and the star on top of the tree flash.

This guide was first published on Dec 21, 2017. It was last updated on Sep 05, 2018. This page (Images) was last updated on Dec 20, 2017.