Sometimes the pre-defined MicroPython images don't cover what we need.
However, the good news is we can design our own custom images. Here's how it is done:
from microbit import *
# build a string with 25 digits using the numbers from 9 to 0
# where 9 is maximum brightness and 0 switches the LED off
img = Image('99999:07770:00500:03330:11111')
display.show(img)
The micro:bit's 25 pixel LED display is arranged as a five row and five column grid. We can create our own image by setting an LED brightness value for each LED. A value of 9
represents the maximum brightness while a value of 0
switches the LED off.
The image defined by a long string of digits. This string is divided up into five sections, separated by a colon (:
) character, with the first section representing the top LED row. And each section contains five digits, with the first digit corresponding to the first column.
After you've downloaded and run this program on the micro:bit modify the string to display your own LED images. It's a good idea to sketch out the pattern designs on paper first using a simple 5x5 grid pattern.
Return to the micro:bit MicroPython Coding Tutorials page.
No comments:
Post a Comment