AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Light show project

Week 29 · Unit 7.6: Sequencing and pattern recognition · 3 lessons
1

Longer light sequences

Computing 7: Unit 7.6, pp. 182–224
GoalExtend a light sequence by planning each new image on a grid and putting its code in the right place.
New words
extend · to make a sequence longer by adding more images to itinsert · to put a new section of code between two sections that are already thereorder · the position of each image in the sequence; it must be the same in the flowchart and in the code
Explanation

You can make a light sequence longer by adding images to it. First change the flowchart. Then draw a grid for each new image and write its rows of 0s and 9s. Each image needs its own show line and its own sleep line. The code must follow the order of the flowchart. If the new image belongs between two old images, insert its code between their code. A quick way is to copy the code for an earlier image, paste it in the right place and edit the rows. Finally run the whole sequence and check that the order is right. If the order of the code is wrong, the lights will move in the wrong order.

StartDisplay a light at the bottomwait 0.4 secondDisplay a light at the topwait 0.4 secondEnd
Worked examples
StartDisplay a light at the bottomwait 0.4 secondDisplay a light in the middlewait 0.4 secondDisplay a light at the topwait 0.4 secondDisplay a clear screenEnd
A lift indicator first shows a light at the bottom and then at the top, which is a sequence of two images. To make it show every floor, the plan is extended: a new image with the light in the middle is inserted between the two old images.
RowImage 1Image 2Image 3
1000000000000900
2000000000000000
3000000090000000
4000000000000000
5009000000000000
Each image has a grid. The light is always in the middle column, and it moves up the board: row 5, then row 3, then row 1. The new image needs only one new grid, because the other grids stay the same.
Python
1from microbit import *
2display.show(Image("00000:00000:00000:00000:00900"))
3sleep(400)
4display.show(Image("00000:00000:00900:00000:00000"))
5sleep(400)
6display.show(Image("00900:00000:00000:00000:00000"))
7sleep(400)
8display.clear()
Output
bottom, middle, top, then the lights go off
This is the finished program. The code for image 2 is copied from image 1 and inserted between image 1 and image 3, and the rows are edited. Every image is followed by sleep(400). The last line clears the screen.
Class activity

Insert a frame (no computer). Write each image of the lift indicator on its own card, with its show line and its sleep line. Put the cards in order and read the program aloud. Your partner then gives you a new card for the light between row 5 and row 3 and you insert it in the right place. Swap two cards on purpose and read the program again: what does the lift do now?

Practice
1
A water tank fills up from the bottom. Image 1: only the bottom row is lit. Image 2: the bottom two rows are lit. Image 3: the bottom three rows are lit. Draw the flowchart, write the three grids as rows of 0 and 9, and write the program. Use waits of half a second and clear the screen at the end.
2
This program should make a lift go down: the top light, then the middle, then the bottom, each for 0.4 second, then clear. Find the two mistakes and write the corrected program.
Python
1from microbit import *
2display.show(Image("00900:00000:00000:00000:00000"))
3display.show(Image("00000:00000:00000:00000:00900"))
4sleep(400)
5display.show(Image("00000:00000:00900:00000:00000"))
6sleep(400)
7display.clear()
3
Look at the program. How long is each image on the lights? What stays lit when the program ends?
Python
1from microbit import *
2display.show(Image("90000:00000:00000:00000:00000"))
3sleep(500)
4display.show(Image("00000:00000:09000:00000:00000"))
5sleep(1000)
6display.show(Image("00000:00000:00000:00090:00000"))
7sleep(250)
4
Explain why the code for a new middle image must be inserted between the code for image 1 and the code for image 3, and not at the end of the program.