Computer 2

Monday, March 9, 2026

Custom Micro:bit Images and Animation

Agenda

  1. Learn how to design your own images for the Micro:bit LED display.
  2. Learn how to put images in a list and loop through them to create an animation.
  3. Start planning your Micro:bit Movie project.

Creating Your Own Images

Design custom pixels on the 5×5 LED grid.

Last class you used built-in images like Image.HEART. Today you will create your own images from scratch using the Image() constructor.

How the Grid Works

The Micro:bit display is a 5×5 grid of LEDs. Each LED can be set to a brightness from 0 (off) to 9 (full brightness). You describe your image as five rows of five digits, with each row separated by a colon (:).

Value Meaning
0 LED off
18 LED on, dim to bright
9 LED fully on

The string you pass to Image() has exactly 5 rows, each with exactly 5 digits, separated by colons. Think of it like drawing on grid paper — each digit is one square.

Example: A Simple Arrow

from microbit import *

arrow = Image('00900:'
              '09990:'
              '90909:'
              '00900:'
              '00900')

display.show(arrow)

Notice that the string is split across multiple lines inside the parentheses to make it easier to read — Python joins them together automatically. The last row has no colon at the end.

Tip: Use grid paper to sketch your image before you type it in. Label each square with a 0 (off) or 9 (on), then read across each row to get your five digits.

Example: A Glowing Center

You are not limited to just 0 and 9. Using values in between creates LEDs that glow at different brightnesses. This image uses three levels: the outer ring is dim (3), the middle ring is medium (5), and the center LED is fully on (9):

from microbit import *

glow = Image('33333:'
             '35553:'
             '35953:'
             '35553:'
             '33333')

display.show(glow)

Try changing the three brightness values to something like 1, 4, and 7 to see the difference. The further apart the values, the more dramatic the contrast between the rings.

Animation with Lists and Loops

String your images together to make something move.

An animation is just a series of images shown one after another, fast enough that your eye sees motion. On the Micro:bit you can do this by putting your custom images in a list and looping through them with a for loop — the same technique you used with built-in images last class.

Example: A Blinking Dot

from microbit import *

frame1 = Image('00000:'
               '00000:'
               '00900:'
               '00000:'
               '00000')

frame2 = Image('00000:'
               '00000:'
               '00000:'
               '00000:'
               '00000')

frames = [frame1, frame2]

while True:
    for frame in frames:
        display.show(frame)
        sleep(400)

Each image in the list is one frame of the animation. The sleep() call controls how long each frame is shown before moving to the next one. A shorter sleep makes the animation faster; a longer sleep makes it slower.

Example: A Ball Bouncing Across the Screen

Here is a longer animation showing a dot moving from left to right across the middle row:

from microbit import *

f1 = Image('00000:'
           '00000:'
           '90000:'
           '00000:'
           '00000')

f2 = Image('00000:'
           '00000:'
           '09000:'
           '00000:'
           '00000')

f3 = Image('00000:'
           '00000:'
           '00900:'
           '00000:'
           '00000')

f4 = Image('00000:'
           '00000:'
           '00090:'
           '00000:'
           '00000')

f5 = Image('00000:'
           '00000:'
           '00009:'
           '00000:'
           '00000')

frames = [f1, f2, f3, f4, f5]

while True:
    for frame in frames:
        display.show(frame)
        sleep(150)

Each frame moves the dot one column to the right. Because the while True loop never ends, the ball wraps back to the left and keeps going forever.

Project: Micro:bit Movie

Make your own animation with at least 9 custom frames.

Assignment

Create a Micro:bit animation that tells a short story or shows something moving. Your movie must have at least 7 custom frames, all drawn using Image() objects stored in a list and shown in a loop.

Requirements

Planning Your Frames

Your teacher will give you grid paper to plan your frames before you start coding. For each frame, write a digit from 0 to 9 in each square — 0 for off, 9 for fully on, and anything in between for partial brightness. Then read across each row to get the five digits for that row of your Image() string.

Think about what you want to animate before you start. Some ideas:

Turning In Your Work

Save your program as lastname_movie.py and upload it to your OneDrive folder. It is due by the end of class on Monday, March 16.