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

Make it work

Week 20 · Unit 8: Be an innovator · 3 lessons
1

A light that follows the room

Computing 4: Unit 8, pp. 104–122
GoalUse a sensor reading to control an output, and work out the result of a formula.
New words
light level · a number from the light sensor: 0 is dark and 255 is very brightbrightness · how brightly the LEDs shine: 0 is off and 255 is the brighteston start · a block whose program runs once when the board startsforever · a block that repeats the blocks inside it again and again
Explanation

A sensor gives the program a number, and the program can use that number to control an output. A night light uses the light level, which goes from 0 (dark) to 255 (very bright). The darker the room, the brighter the LEDs should shine. So the program works out brightness = 255 − light level. This calculation is the process. In a dark room the light level is 0, so the brightness is 255. In a bright room the light level is 255, so the brightness is 0 and the moon disappears. The block on start draws a moon once. The forever block keeps measuring the light and changing the brightness.

draw the moon onceshow ledson startkeep adjustingset brightness255-light levelforever
Worked examples
RoomLight levelBrightness
dark bedroom0255
dim hall100155
room with a lamp20055
sunny kitchen2550
Work out the brightness for different rooms with brightness = 255 − light level.
Program Aset brightnesslight levelforeverProgram Bset brightness255-light levelforever
Why subtract from 255? Program A makes the LEDs brightest in a bright room, which is no use for a night light. Program B turns the number round, so the LEDs are brightest in the dark.
The night light uses an input, a process and an output. The sensor measures the light, the program subtracts, and the LED display shows the result.
Class activity

Human night light (with family): one person is the light sensor and secretly picks a number from 0 to 255 on a card for “how bright the room is”. The other person is the program and works out 255 minus the number. Then they show the brightness by holding a torch or their hands apart: very close together for a low brightness and wide apart for a high one. Do five rounds and write the numbers in a table. Which light levels give the brightest LEDs?

Practice
1
The light level is 40. What brightness does the night light program set?
2
What do the LEDs do when the light level is 255? Why?
3
Complete the table for the night light. Which room gets the brightest moon?
Light levelBrightness (255 − light level)
60?
120?
210?
4
In the night light, which block runs only once at the start and which block keeps repeating? What would go wrong if the set brightness block were inside on start?