Week 29 · Unit 7.6: Sequencing and pattern recognition · 3 lessons
2
Bright and dim
Computing 7: Unit 7.6, pp. 182–224
GoalUse the numbers 1 to 8 to set the brightness of a light, and plan a fading sequence.
New words
brightness · how strongly a light shines; on the micro:bit it is a number from 0 (off) to 9 (full)fade · to change the brightness step by step, for example from dim to brightclear screen · an image where every light is 0, so that all the lights are off
Explanation
Each light on the micro:bit can shine at ten levels. The number 0 means off and 9 means full brightness. The numbers 1 to 8 are in between, and about 4 or 5 is half brightness. In an image, you can use different numbers for different lights to make a glow. To make a fade, show the same shape several times, with a higher number each time. Plan the numbers on a grid first. Then write the code, with a sleep after each image so that the eye can see each step. An image with 0 in every place switches all the lights off, so it can be the last step of a sequence.
Number
How the light shines
0
off
1–2
very dim
3–4
dim
5
about half
6–8
bright
9
full brightness
Worked examples
Row
Bright glow
1
00000
2
03630
3
06960
4
03630
5
00000
A glow in the middle of the board. The centre is brightest, the lights next to it are medium and the corner lights of the ring are dim. The grid holds the numbers.
A fade-in plan. The glow starts dim (numbers 1, 2 and 3), then becomes bright (3, 6 and 9), and finally all the lights go off. The flowchart has the three images with waits.
The program for the plan. The shape of the numbers is the same in the first two images; only the brightness changes. The third image is all zeros.
Class activity
Shade the scale (no computer). Draw a 5 × 5 grid on paper and shade the squares with a pencil, from white (0) to very dark (9). Write the numbers inside. Then make a partner’s grid: call out a row such as 03630 and they shade it. Draw the three steps of a candle getting brighter and write the numbers for each step.
Practice
1
The lamp below is shown at full brightness. Write the grid rows for a fade-in sequence of three images: all the lit lights at 3, then at 6, then at 9. How many lights are lit in each image?
The lit lights are in rows 1 and 5 (three each) and the middle of rows 2, 3 and 4. That makes 3 + 1 + 1 + 1 + 3 = 9 lights. Image 1: 03330, 00300, 00300, 00300, 03330. Image 2: 06660, 00600, 00600, 00600, 06660. Image 3: 09990, 00900, 00900, 00900, 09990. Nine lights are lit in each image.
2
Read this program. Which light is the brightest, how bright is it, and how many lights are on?
The brightest light is the bottom-left light, number 5, which is only about half brightness. No light is at 9. The numbers 1, 2, 3, 4 and 5 are in rows 1 to 5, so 1 + 2 + 3 + 4 + 5 = 15 lights are on and 10 lights are off.
3
A fade-in should start dim, then become bright, then switch off. The programmer wrote the images in the wrong order. Describe what the lights do and how to fix the program.
The program shows the bright glow first, then the dim glow, so it fades out, and then it clears. To fix it, swap the first two images, or swap the two blocks of code, so that the dim glow comes first.
4
Give two reasons why controlling brightness is useful in a light display.
A fading light looks smoother and can catch the eye better than a light that just switches on and off. Different brightness levels can show different meanings, for example a dim light for waiting and a bright light for an alert. Brightness can also make an image look more detailed.