Skip to content

Activity

Shining sunbeams

Beginner | MakeCode, Python | LED display | Iteration, Sequence

Step 1: Make it

What is it?

Use the sun icon from the Here comes the sun to make a sunbeam animation.

sun animation on micro:bit display

How it works

  • The program shows a sequence of sun pictures on the LED display based on the one we made in the Here comes the sun project.
  • It waits 500 milliseconds (half a second) between showing each image to allow you to see it before displaying the next.
  • The sequence makes an animation of sunbeams coming from the centre of the sun.
  • The sequence repeats for as long as your micro:bit has power because the instructions are inside a forever, or infinite, loop.
  • Computers are often used to help animators make cartoons and films, creating an illusion of movement by showing a sequence of slightly different images one after another.

What you need

  • micro:bit (or MakeCode simulator)
  • MakeCode or Python editor
  • battery pack (optional)
  • squared paper to sketch your own sunbeam designs (optional)

Step 2: Code it

1from microbit import *
2
3while True:
4    display.show(Image(
5        "00000:"
6        "00900:"
7        "09990:"
8        "00900:"
9        "00000"))
10    sleep(500)
11    display.show(Image(
12        "00000:"
13        "09990:"
14        "09990:"
15        "09990:"
16        "00000"))
17    sleep(500)
18    display.show(Image(
19        "90909:"
20        "09990:"
21        "99999:"
22        "09990:"
23        "90909"))
24    sleep(500)

Step 3: Improve it

  • Speed up or slow down the animation by changing the delay of 500 milliseconds.
  • Use your own design for the sun and its rays.
  • In Python, use a range of numbers from 1 to 9 to show the sun’s rays getting dimmer as they get further from the centre.