Skip to content

Activity

Teleporting duck

Beginner | MakeCode, Python | Accelerometer, Radio | Communication, Radio waves

Step 1: Make it

What is it?

Make a duck fly invisibly through the air from one micro:bit to another.

How it works

  • Flash this program onto two micro:bits, shake one and a duck appears to travel magically through the air from one to the other. Shake the other to send it back.
  • It’s not really magic. It uses the micro:bit’s radio function to send data from one micro:bit to another when the accelerometer detects a shake gesture.
  • The program first sets the radio group to 23. Groups are like channels on walkie-talkie radios; they can be number between 0 and 255. It doesn’t matter what number you pick as long as your friend’s micro:bit is using the same group number, and no-one else nearby is using the same group.
  • When you shake it, it sends the word ‘DUCK’ on that radio group and clears the screen. If either micro:bit receives a radio message (any radio message), a duck icon appears on its display, so you should only ever have 1 duck visible at any time.

What you need

  • 2 micro:bits (or MakeCode simulator)
  • MakeCode or Python editor
  • battery packs (optional)
  • a friend to play with

Step 2: Code it

1from microbit import *
2import radio
3radio.config(group=23)
4radio.on()
5
6while True:
7    message = radio.receive()
8    if message:
9        display.show(Image.DUCK)
10    if accelerometer.was_gesture('shake'):
11        display.clear()
12        radio.send('duck')
13

Step 3: Improve it

  • Find out how far apart you can go for this still to work.
  • Teleport other animals. Would you need to change the picture, the message – or both?
  • What happens if more than 2 of you use the same radio group? How can you fix this?