← Teacher guide

Radio duel

Students turn the reaction game into a two-player race over radio, using a shared message code, a function to remove copied blocks, a true/false variable and a score.

micro:bit: talk and play · Final challenge: Reaction duel · about 60 minutes · Open the student lesson

Classroom resources

Load these into Waypoints Prepare: choose Load URL and paste the copied address, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.

Students will be able to

Timing

Predict, Run, Investigate 12 min · Milestone 1 10 min · Milestone 2 15 min · Milestone 3 15 min · Fair play 5 min

Before class

Both micro:bits run the same program. The players agree a code: 0 = get ready, 1 = go, 2 = I pressed first (and 3 = I won the match, in Milestone 3). Whoever presses B sends 0, waits, sends 1 and shows its own heart; the other shows its heart when 1 arrives. racing is true only while a round is on, so only the first press counts, and a late press after receiving 2 does nothing. Milestone 1 is a refactor: the starter shows the heart and sets racing in two places (a design fault: copies must be kept the same by hand), and students fold them into one function. In the simulator, two micro:bits appear; one student can play both sides to test.

Running the lesson

  1. Predict: the heart shows on both. Ask how the second micro:bit knows when (message 1).
  2. Investigate: the match names the code. The two-copies question is why Milestone 1 exists.
  3. Milestone 1: defs 1 and calls 2 is the check. Ask: if you change the heart now, how many places change?
  4. Milestone 2: read the A event aloud: 'if we are racing, stop, tell the other player, celebrate'.
  5. Milestone 3: a score variable and message 3. Give pairs real micro:bits for this if you have them: it is far more fun.
  6. Fair play: in a room of micro:bits, each pair needs its own group.

The hard part (on purpose)

Keeping two micro:bits in step with a code of messages. Ask them to trace one round on paper: who sends what, and who checks it.

When students get stuck

What you will seeA question to askThe fix
The heart only shows on one micro:bit.Is message 1 sent, and does the receiver check for 1?Send 1 before calling go, and in on radio received call go when receivedNumber = 1.
Both players see a happy face.Do you check racing before counting a press?In A, only act if racing; set racing to false straight away.
The check for Milestone 1 does not tick.How many call go blocks are there?Call go in both places: after sending 1, and when 1 arrives.

Answers to the checks

  1. Predict: Player 1 presses B. When the heart appears, where does it show?
    On both. Player 1's micro:bit sends 1 and shows its own heart; player 2's shows its heart when the 1 arrives.
  2. The code: Match each message with what it means in the duel.
    0 → A. get ready: clear the screen, no racing yet; 1 → C. go: show the heart and start racing; 2 → B. I pressed first: you lose this round
  3. Two copies: The blocks 'show heart, set racing to true' appear in two places. You change the heart to a diamond in one place only. What goes wrong?
    The player who pressed B sees a different signal from the other player
    Copied blocks have to be changed in every copy. Forget one and the two players see different signals: an unfair race. A function keeps one copy.
  4. In Python: The receiving part in Python. Match each line with what it does.
    if receivedNumber == 0: → B. checks for get ready; elif receivedNumber == 1: → A. otherwise, checks for go; racing = True → C. remembers that a round is on
  5. Fair play: Two real micro:bits play the duel in a classroom where another pair also uses group 7. What could go wrong?
    The other pair's messages arrive too, so their go or win messages mix into your race
    Every micro:bit in group 7 hears every message. Each pair needs its own group number, as in the Send and receive lesson.

Solutions

One possible solution for each task. Other correct programs are fine.

Milestone 1: one go function

The program as blocks
Show as code
let racing = false
radio.setGroup(7)
function go () {
    basic.showIcon(IconNames.Heart)
    racing = true
}
input.onButtonPressed(Button.B, function () {
    radio.sendNumber(0)
    racing = false
    basic.clearScreen()
    basic.pause(randint(1000, 4000))
    radio.sendNumber(1)
    go()
})
radio.onReceivedNumber(function (receivedNumber) {
    if (receivedNumber == 0) {
        racing = false
        basic.clearScreen()
    } else if (receivedNumber == 1) {
        go()
    }
})

Milestone 2: first press wins

The program as blocks
Show as code
let racing = false
radio.setGroup(7)
function go () {
    basic.showIcon(IconNames.Heart)
    racing = true
}
input.onButtonPressed(Button.B, function () {
    radio.sendNumber(0)
    racing = false
    basic.clearScreen()
    basic.pause(randint(1000, 4000))
    radio.sendNumber(1)
    go()
})
input.onButtonPressed(Button.A, function () {
    if (racing) {
        racing = false
        radio.sendNumber(2)
        basic.showIcon(IconNames.Happy)
    }
})
radio.onReceivedNumber(function (receivedNumber) {
    if (receivedNumber == 0) {
        racing = false
        basic.clearScreen()
    } else if (receivedNumber == 1) {
        go()
    } else if (receivedNumber == 2) {
        if (racing) {
            racing = false
            basic.showIcon(IconNames.Sad)
        }
    }
})

Milestone 3: first to three

The program as blocks
Show as code
let wins = 0
let racing = false
radio.setGroup(7)
function go () {
    basic.showIcon(IconNames.Heart)
    racing = true
}
input.onButtonPressed(Button.B, function () {
    radio.sendNumber(0)
    racing = false
    basic.clearScreen()
    basic.pause(randint(1000, 4000))
    radio.sendNumber(1)
    go()
})
input.onButtonPressed(Button.A, function () {
    if (racing) {
        racing = false
        radio.sendNumber(2)
        wins += 1
        if (wins == 3) {
            radio.sendNumber(3)
            basic.showIcon(IconNames.Yes)
        } else {
            basic.showIcon(IconNames.Happy)
        }
    }
})
input.onButtonPressed(Button.AB, function () {
    basic.showNumber(wins)
})
radio.onReceivedNumber(function (receivedNumber) {
    if (receivedNumber == 0) {
        racing = false
        basic.clearScreen()
    } else if (receivedNumber == 1) {
        go()
    } else if (receivedNumber == 2) {
        if (racing) {
            racing = false
            basic.showIcon(IconNames.Sad)
        }
    } else if (receivedNumber == 3) {
        basic.showIcon(IconNames.Skull)
    }
})

Stretch and support

Stretch: Add an early-press penalty: pressing A before the heart sends 4, and the other player wins the round.

Support: Run Milestone 3 in pairs: one student builds the winner side (counting and sending 3), the other the loser side (receiving 3).

Exit ticket

In a duel, the first micro:bit radios 1 just before it shows a heart, and the second shows a heart when 1 arrives. Why do the two hearts appear at almost the same time?

The first sends message 1 just before showing its heart, and the second shows its heart as soon as 1 arrives.

What each step is for

Where it leads

Two optional lessons go further: Fake-outs and levels (one player, harder rules) and Tournament (a scoreboard list and a round function). Class ideas: a class knockout tournament; a quiz buzzer for real class quizzes.