In the last two lessons, you have learned to use the LEDs in your Hummingbird kit. There are also LEDs on the micro:bit. These 25 tiny LEDs are arranged in a 5 by 5 grid. In this lesson, you will write programs that use these LEDs to make letters and pictures.
Lesson 3 – micro:bit Display
To write letters and numbers on the micro:bit, use the print() method. This method takes a string parameter, which is text within quotation marks (single or double quotes). The string must have 15 or fewer characters and should contain only digits and English letters (upper or lower case).
The print() method displays the string on the micro:bit LED array one letter at a time. For example, the code below shows the letter ‘H’ then the letter ‘i’ on the micro:bit.
Print your name on the micro:bit. Make sure that the program pauses long enough to display all the letters before the program ends.
To display different patterns on the micro:bit, use the setDisplay() method. This method sets the LED array of the micro:bit to display a pattern defined by a list of length 25. Each value in the list must be 0 (off) or 1 (on). The first five values in the array correspond to the five LEDs in the first row, the next five values to the second row, etc. For example, this code lights up the top and bottom rows on the micro:bit display. This code shows the numbers for each micro:bit row on a different line. This isn’t required in Python, but it makes the code easier to read.
Use a for loop to blink the micro:bit display between two different patterns. If you blink quickly between different patterns, you can create simple animations like a bunny hopping up and down.
The setDisplay() method sets all of the micro:bit LEDs at the same time. To turn individual micro:bit LEDs on or off, use the setPoint() method. This method takes three parameters. The position of the LED is given by the row and column parameters, which should both be between 1 and 5. The third parameter is the value of the LED, which must be 0 (off) or 1 (on).
Modify the code from the previous exercise to turn all of the micro:bit LEDs on and then turn the corners off.