GoalSearch a data table with two rules and write a micro:bit algorithm with a repeat step.
New words
record · one row of a table, holding all the facts about one thingfield · one column of a table, such as colour or weightinput device · a part that sends information to the computer, such as a button or a light sensoroutput device · a part that gives out information, such as an LED display or a speaker
Explanation
A table keeps data in rows and columns. Each row is a record, and each column is a field. To search a table, read the rule and check the records one by one. With two rules joined by AND, a record must pass both. Each field has a data type: Text, Number, Date/Time or Yes/No. A micro:bit shows how inputs and outputs work. A button, a sensor or shaking is an input. The LED display and a speaker are outputs. To plan a micro:bit program, we split it into parts and write an algorithm with a repeat step. A step that repeats steps 2 to 4 two more times plays the round 3 times in all.
Tool
Colour
Weight (kg)
Needs oil
Spade
green
4
no
Rake
green
2
no
Hoe
red
1
yes
Shears
red
2
yes
Trowel
blue
1
no
Fork
green
3
no
Worked examples
Tool
Green?
Over 2 kg?
Both?
Spade
yes
yes
yes
Rake
yes
no
no
Hoe
no
no
no
Shears
no
no
no
Trowel
no
no
no
Fork
yes
yes
yes
Search the tool table with two rules: the colour is green and the weight is more than 2 kg. Check each record against both rules.
Step
Instruction
1
Start program when button A is pressed
2
Show heart icon
3
Wait 1 second
4
Clear screen
5
Repeat steps 2 to 4 two more times
6
Stop program
A micro:bit gadget. Button A starts it and the heart is shown 3 times in all. Each round has the same three steps.
Part
Input or output?
button A
input
light sensor
input
LED display
output
speaker
output
Sorting parts of a micro:bit into inputs and outputs.
Class activity
Detective table (with family): make a table of five things in your home, for example pans, books or shoes. Choose three fields, for example name, colour and weight, and fill in the records. Write one search with a single rule and one with two rules joined by AND. Ask someone to find the answers. Then think of a gadget with a button and a light, and write its algorithm with a repeat step.
Practice
1
In the tool table, how many fields and how many records are there?
4 fields and 6 records.
2
Search the tool table for needs oil is yes AND weight is 2 kg. Which tool is found?
The shears. The hoe needs oil but weighs 1 kg.
3
Say the data type of each data item from the tool table.
Data item
Field
Data type
3
Weight (kg)
?
Spade
Tool
?
yes
Needs oil
?
3 is Number, Spade is Text, and yes in the field Needs oil is Yes/No.
4
A gadget shows the diamond icon for 2 seconds each time. Button B starts it and it shows the diamond 4 times in all. Write step 5.