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
3

Project: model harbour lighthouse

Computing 7: Unit 7.6, pp. 182–224
GoalPlan, write and test a small lighthouse program on paper, and then evaluate it.
New words
project plan · a plan that says what the program must do, which input and output it uses, and how it will be testedevaluate · to judge how well something works and to say how it could be betterrecommendation · a suggestion for an improvement, based on what the tests and the users showed
Explanation

Problem: a model harbour in the school hall needs a lighthouse. When a visitor presses A, the lamp sweeps its beam from the left, down and to the right, and then goes off. Start with a project plan. Write what the program must do, the input, the output, and how it will be tested. Draw a flowchart in which the sweep is a sub-routine. Plan each image on a grid, with brightness numbers. Write the program. Then apply a test plan, find and fix any bug, and evaluate. Do the flowchart and the lights agree? Did pressing A start the lamp? Can each image be seen clearly? What would make the lighthouse better?

RowImage 1: beam leftImage 2: beam downImage 3: beam right
1009000090000900
2050000050000050
3500000050000005
4000000050000000
5000000000000000
Worked examples
Part of the planAnswer
What it must dosweep a beam left, down and right, when a visitor presses A
Inputbutton A
Outputthree images; the lamp (the top light) is at brightness 9 and the beam is at brightness 5
Sequenceimage 1, image 2, image 3, each for half a second, then clear the screen
How to testa test plan with four tests
The project plan for the lighthouse. Each row answers one planning question.
StartIs button A pressed?yesnorun sub-routine: SweepDisplay a clear screenEnd
The main flowchart. The sweep is a sub-routine, drawn here as a box that says run sub-routine. When A is not pressed, the lamp stays off. The sub-routine shows the three images with a wait of 0.5 second after each, and then clears the screen.
Python
1from microbit import *
2while True:
3    if button_a.is_pressed():
4        display.show(Image("00900:05000:50000:00000:00000"))
5        sleep(500)
6        display.show(Image("00900:00500:00500:00500:00000"))
7        sleep(500)
8        display.show(Image("00900:00050:00005:00000:00000"))
9        sleep(500)
10        display.clear()
Output
when A is pressed: beam left, down, right; then lights off
The program. The grids from the plan are copied row by row. The program checks button A again and again. Each time A is pressed, the lines under the if (the three images, each followed by its wait, and then the clear line) do the job of the Sweep sub-routine in the flowchart.
Class activity

Make it on paper (no computer). Plan your own sweep for a toy lighthouse or a pretend ship: draw the project plan table, the flowchart and three grids with brightness numbers, and write the program. Then give the program and the test plan to a partner. The partner plays the micro:bit: they read your code line by line and draw what the lights show, and they mark each test pass or fail. If you have a computer or tablet, flash the program to a micro:bit with an adult.

Practice
1
Copy the test plan for the lighthouse and write the expected outcomes by hand, before testing.
TestWhat is testedTest dataExpected outcomePass/fail
1A starts the sweepA pressed?
2The sweep orderA pressed?
3The sweep endsA pressed?
4Idle stateno button pressed?
2
Ben copied the code for image 1 to make image 3, but he forgot to edit it. Test 2 fails. Say what the lights do and write the correct third block.
Python
1from microbit import *
2while True:
3    if button_a.is_pressed():
4        display.show(Image("00900:05000:50000:00000:00000"))
5        sleep(500)
6        display.show(Image("00900:00500:00500:00500:00000"))
7        sleep(500)
8        display.show(Image("00900:05000:50000:00000:00000"))
9        sleep(500)
10        display.clear()
3
Three visitors tried the lighthouse. Write three recommendations to improve it, using their comments.
VisitorComment
Visitor 1The beam moves too fast for me to follow.
Visitor 2It jumps from left to down. It is not smooth.
Visitor 3The beam is too dim to see from the back of the hall.
4
Choose your own problem: a crossing light for a model railway, or a signal for a toy bus stop. Write a short project plan with the same five parts as the lighthouse plan.