Use the number that arrives by radio to do something different for each message, and send words as well as numbers.
A garage door opener has one receiver but two buttons: open and close. The receiver reads which code arrived and acts on it.
Last lesson every message did the same thing: a heart. But on radio received also tells you what arrived. receivedNumber holds the number that was sent, so the receiver can ask about it with if.
Make your prediction first. Help opens once you've locked it in.

radio.setGroup(1)
input.onButtonPressed(Button.A, function () {
radio.sendNumber(1)
})
input.onButtonPressed(Button.B, function () {
radio.sendNumber(2)
})
radio.onReceivedNumber(function (receivedNumber) {
if (receivedNumber == 1) {
basic.showIcon(IconNames.Heart)
} else if (receivedNumber == 2) {
basic.showIcon(IconNames.Sad)
}
})
A sends 1 and B sends 2. One on radio received block checks which arrived.
Press A, then B, on one micro:bit. Watch the other.

radio.setGroup(1)
input.onButtonPressed(Button.A, function () {
radio.sendNumber(1)
})
input.onButtonPressed(Button.B, function () {
radio.sendNumber(2)
})
radio.onReceivedNumber(function (receivedNumber) {
if (receivedNumber == 1) {
basic.showIcon(IconNames.Heart)
} else if (receivedNumber == 2) {
basic.showIcon(IconNames.Sad)
}
})

radio.setGroup(1)
input.onButtonPressed(Button.A, function () {
radio.sendNumber(1)
})
input.onButtonPressed(Button.B, function () {
radio.sendNumber(2)
})
radio.onReceivedNumber(function (receivedNumber) {
if (receivedNumber == 1) {
basic.showIcon(IconNames.Heart)
} else if (receivedNumber == 2) {
basic.showIcon(IconNames.Sad)
}
})
def on_received_number(receivedNumber):
if receivedNumber == 1:
basic.show_icon(IconNames.HEART)
elif receivedNumber == 2:
basic.show_icon(IconNames.SAD)
radio.on_received_number(on_received_number)
elif is Python's short way to write else if.
What does the receiver show for each number that arrives?
| receivedNumber | shows |
|---|---|
| 1 | |
| 2 | |
| 5 |
The receiver in Python. Match each line with what it does.
Make a shake send 3, and the receiver show a surprised face when 3 arrives.
Drag in on shake with radio send number 3.
Click + on the receiver's if to add another else if: receivedNumber = 3.
send string sends a word, and on radio received receivedString holds the word that arrived. Make A+B send hi, and the receiver show it.
radio send string is in Radio. Put it in on button A+B pressed, with hi.
Drag in on radio received receivedString, with show string receivedString.
A shake sends 3, and the receiver shows a surprised face for 3.
This ticks by itself when your blocks do what is asked.
A+B sends the word hi, and the receiver shows the word that arrived.
This ticks by itself when your blocks do what is asked.
Last lesson's program, on three micro:bits.

radio.setGroup(1)
input.onButtonPressed(Button.A, function () {
radio.sendNumber(1)
})
radio.onReceivedNumber(function (receivedNumber) {
basic.showIcon(IconNames.Heart)
basic.pause(500)
basic.clearScreen()
})
Make bike signals by radio: the rider presses buttons on one micro:bit, and the one on the back of the bike shows the signal.
Three senders: A sends 1, B sends 2, shake sends 3.
One on radio received, with if receivedNumber = 1 … else if = 2 … else if = 3.
Bike signals by radio: A, B and shake send three different numbers, and the other micro:bit shows a different picture for each.
This ticks by itself when your blocks do what is asked.
This doorbell sends a word instead of a number. Make it send your name, then make B send a different message, such as "come in".
Students use receivedNumber to do something different for each radio message, and send words with send string. About 40 minutes.
Open the teacher guide: answers, solutions, slides and a worksheet.
on radio received runs for every number that arrives, and receivedNumber (drag it out of the block) holds which number it was. One receiver block with if … else if handles every message; a second on radio received block greys out. send string and on radio received receivedString do the same for words. Each number is a code both micro:bits agree on: 1 means left, 2 means right.
One receiver for every message. Ask what receivedNumber holds when B is pressed.
Stretch: Make a two-way chat: each micro:bit sends 1 for 'yes' and 2 for 'no', and shows a tick or cross when the other answers.
Support: Give students the receiver with if … else if already built, and ask them to add the senders.
Next lesson: a list both micro:bits share turns the numbers into words. Class idea: a quiz buzzer where A and B are two answers.