Custom Images

You can create custom images from individual pixels on the micro:bit module’s display by using display.set_pixel

The set_pixel method has three parameters: x, y, and b:

    display.set_pixel(x, y, b)

The arguments for x and y indicate the pixel's position in the micro:bit module display's coordinate plane. The b argument controls the brightness (0-9) of the pixel.

Example script: two_pixels

To see how this works, try the following program which lights up two LEDs.

  • Enter, save, and flash the script two_pixels to your micro:bit.
# two_pixels

from microbit import *

display.set_pixel(0, 0, 9)
display.set_pixel(1, 3, 4)

How the two_pixels script works

The first statement display.set_pixel (0, 0, 9)lights up the pixel is located at (0,0) which is the top left of the display. It is set to the maximum brightness of 9.

The second statement display.set_pixel (1, 3, 4)  lights up the pixel located at (1,3), which is in the second column from the left and down 4 rows. The brightness is only 4, so it is significantly dimmer than the first pixel.

Example script: medium_box

Using the following script, see how a medium size box can be made by lighting up 8 pixels in the middle of the micro:bit module’s display.

  • Enter, save, and flash the script medium_box to your micro:bit
# medium_box

from microbit import *

display.set_pixel(1, 1, 9)
display.set_pixel(1, 2, 9)
display.set_pixel(1, 3, 9)
display.set_pixel(2, 1, 9)
display.set_pixel(2, 3, 9)
display.set_pixel(3, 1, 9)
display.set_pixel(3, 2, 9)
display.set_pixel(3, 3, 9)

Your Turn

  • Try creating a large box that uses all of the pixels on the outside edge of the display.
  • Try writing a program for a custom image of your own creation.