Skip to content

Display Built-in Images

Level Beginner
Board V1 & V2
Parts micro:bit

What you'll build

Animate the LED matrix by stepping through nine built-in images, one per second.

Code

2 display images.py
'''
Example: Print built-in Images on LED matrix in micro:bit
By: Meqdad Darwish
Ref: https://microbit-micropython.readthedocs.io/en/latest/tutorials/images.html
'''
from microbit import *

while True:
    display.show(Image.HEART)
    sleep(1000)  # 2000 = 2 sec.
    display.show(Image.HEART_SMALL)
    sleep(1000)
    display.show(Image.HAPPY)
    sleep(1000)
    display.show(Image.SMILE)
    sleep(1000)
    display.show(Image.SAD)
    sleep(1000)
    display.show(Image.CONFUSED)
    sleep(1000)
    display.show(Image.ANGRY)
    sleep(1000)
    display.show(Image.ASLEEP)
    sleep(1000)
    display.show(Image.SURPRISED)
    sleep(1000)

How it works

MicroPython ships with dozens of ready-made 5×5 images on the Image class (Image.HEART, Image.HAPPY, Image.SAD, …). Each display.show() replaces what is on screen, and sleep(1000) holds it for a second.

See the full list in the MicroPython images tutorial.

Try this next

  • Put the images in a list and loop over it instead of repeating show/sleep.
  • Pass the whole list to display.show(images, delay=500) to animate in one line.
  • Design your own image — see Display DIY Images.