Skip to content

← Grade 8 Computing

Exam practice

Every question from the end of every unit, with hints and answers to open. After you check an answer, mark how you did, and come back to the ones you didn’t get.

10 questions

Unit 7 · Physical Computing

a.

Explain these words, with an example of each: physical computing, sensor, microcontroller, threshold, polling.

Answer
  • Physical computing: programming a computer that senses the world and acts on it. Example: a night light that switches on when it gets dark.
  • Sensor: an input device that measures something in the world by itself. Example: a temperature sensor in a rice cooker; a light sensor.
  • Microcontroller: a small computer (processor, memory, storage and pins) on one chip, usually running one program. Example: the chip in a micro:bit, a remote control or a washing machine.
  • Threshold: the number a reading is compared with, to decide between two actions. Example: in if light < 50:, 50 is the threshold between dark and light.
  • Polling: checking an input again and again in a loop. Example: while True: asking button_a.is_pressed() hundreds of times a second.
b.

Describe each device as inputs → program → outputs: i. an automatic hand dryer in a restaurant’s washroom, ii. a digital rice cooker, iii. a traffic light with a button for people on foot.

Answer
  • i.Hand dryer. Input: a sensor that notices hands under it. Program: when hands are there, blow; stop a moment after they go. Outputs: the fan’s motor and the heater.
  • ii.Rice cooker. Inputs: the buttons (which kind of rice, the time to be ready) and the temperature sensor under the pot. Program: soak, heat hard, then gently, then keep warm, checking the temperature again and again. Outputs: the heater and the display.
  • iii.Traffic light. Inputs: the button for people on foot, and at many junctions sensors that notice waiting cars. Program: change the lights in the right order with the right times, and give people a turn to cross after the button is pressed. Outputs: the lamps (and at some crossings a beeping sound for people who can’t see the lamps).
c.

Draw a 5 × 5 grid and shade the LEDs this program lights. What picture is it?

from microbit import * display.show(Image("09090:09090:00000:90009:09990"))
Answer

Row by row from the top (9 is lit, 0 is off):

x = 0 1 2 3 4
y = 0 ■ ■
y = 1 ■ ■
y = 2
y = 3 ■ ■
y = 4 ■ ■ ■

Two eyes and a smiling mouth: a happy face.

d.

Write a program for the board that shows Image.YES while button A is held, Image.NO while button B is held, and nothing when neither is pressed. (Try it on the “Your device” board.)

Answer
from microbit import * while True:    if button_a.is_pressed():        display.show(Image.YES)    elif button_b.is_pressed():        display.show(Image.NO)    else:        display.clear()

is_pressed() is right here, not was_pressed(): the picture must stay for as long as the button is held.

e.

What is the difference between button_a.is_pressed() and button_a.was_pressed()? Give a device for which each is the right choice.

Answer

is_pressed() answers whether A is down at this moment: True all the time it is held. was_pressed() answers whether A has been pressed since the program last asked, then forgets that press: one True for each press, even a quick one made during a sleep.

  • is_pressed(): a doorbell that rings while the button is held, or a torch that lights while you press.
  • was_pressed(): a counter for people coming in, a score in a game, a button that moves to the next picture: anything where each press must count once.
f.

A night light uses if light < 50: to switch on. At dusk, the light level goes up and down between 48 and 52 for several minutes, as clouds pass. What will the night light do? How could you make it better?

Hint

Try it: on the night-light board, move the Light slider back and forth across 50. Then think about using two different numbers.

Answer

It will flicker, switching on and off every time the reading crosses 50. Better: use two thresholds. Switch on when the light falls below 40, and switch off only when it rises above 60; between 40 and 60, leave it as it is. To do that, the program remembers whether the light is on in a variable:

from microbit import * on = Falsewhile True:    light = display.read_light_level()    if light < 40:        on = True    elif light > 60:        on = False    if on:        display.show(Image("99999:99999:99999:99999:99999"))    else:        display.clear()    sleep(500)

Thermostats in fridges and water heaters work the same way, with a gap between switching on and switching off, so they don’t click on and off every few seconds.

g.

Design a device that warns when the air in a seedling nursery gets hotter than 35 °C. Give the need, a table of inputs and outputs, the rules in words, a program, and at least four tests with chosen inputs.

Answer

The need: seedlings can wilt and die on a hot day; the gardener wants a warning in time to open the shade or water them.

What Why
input temperature sensor to measure how hot it is
input button A to show the temperature now
output speaker a warning sound
output LEDs a sad face while it is too hot; the temperature when A is pressed

Rules: if the temperature is above 35 °C, show a sad face and beep every few seconds; otherwise show a happy face. When A is pressed, scroll the temperature.

from microbit import *import music while True:    if button_a.was_pressed():        display.scroll(str(temperature()) + " C")    if temperature() > 35:        display.show(Image.SAD)        music.pitch(880, 300)        sleep(2000)    else:        display.show(Image.HAPPY)        sleep(500)

Tests (on the Your device board, with the Temperature slider), each written down before running:

Test Temperature Expected
1 25 °C happy face, no sound
2 35 °C happy face: 35 is not above 35
3 36 °C sad face and a beep every 2 s or so
4 36 °C, then back to 30 °C the beeping stops and the happy face comes back
5 press A at 28 °C scrolls “28 C”

The board’s sensor measures its own chip, so before trusting the device, put it beside a real thermometer for a day and compare.

h.

Write a dice for ludo: when the board is shaken, it shows a random number from 1 to 6.

Answer
from microbit import *import random while True:    if accelerometer.was_gesture("shake"):        display.show(random.randint(1, 6))

random.randint(1, 6) gives a whole number from 1 to 6, each equally likely, and display.show shows a single digit straight away.

i.

Give three differences between a micro:bit and an Arduino Uno. What is the same about them?

Answer

Differences (any three):

  • The micro:bit has LEDs, buttons, sensors and a speaker built in; the Arduino Uno has almost nothing built in, and you connect your own parts to its pins.
  • The micro:bit is programmed in MicroPython, blocks or JavaScript; the Arduino Uno usually in the Arduino language, based on C++.
  • The micro:bit can be programmed from a phone by Bluetooth or from a browser; the Arduino usually from the Arduino IDE on a computer, by USB.
  • The micro:bit runs on two AAA cells; the Uno usually on USB, a 9 V battery or an adapter.

The same: each is a board with a microcontroller that runs one program over and over, taking in inputs, deciding, and switching outputs. A program is written on a computer and flashed onto the board, which then runs on its own.

j.

Why must a device that switches a water pump be connected through a relay, and why should a student never wire a board to the mains?

Answer

The board’s outputs give only a tiny current at 3 to 5 volts, far too little to run a pump’s motor. A relay is a switch worked by electricity: the board’s small current switches the relay, and the relay switches the pump’s big current. The mains in Nepal is 230 volts, which can kill and start fires. A board and the wires a student builds are made for low voltage only, so anything on the mains must use a relay module made for the job and be built and checked by an adult who knows electrical work.