Step 1: Make it
What is it?
Use micro:bit’s radio feature to answer questions in secret.
How it works
- Flash this program on to two micro:bits. You and a friend ask each other questions that have ‘yes’ or ‘no’ as the answer.
- Press input button A to send ‘yes’ and button B to send ‘no’ messages. A tick or cross will flash on both micro:bits’ LED display outputs for half a second.
- The program uses radio to send your answer secretly - no-one (except your partner) can hear the radio signal.
- When a radio message is received, the program uses selection to test the message: if the received message is equal to ‘yes’, then it shows a tick on the LED display, but if the message is equal to ‘no’ then it shows a cross.
- Make sure the radio group number is the same on both micro:bits – you can use any number between 0 and 255.
- If lots of you are using this program in the same place, you’ll want to make sure each pair of people has their own radio group number.
- Keep your radio group number a secret if you don't want anyone snooping on your messages!
What you need
- Two micro:bits (or MakeCode simulator)
- MakeCode or Python editor
- battery pack (optional)
- a friend and a secret to share!
Step 2: Code it
1from microbit import *
2import radio
3radio.config(group=7)
4radio.on()
5
6while True:
7 message = radio.receive()
8 if message:
9 if message == 'yes':
10 display.show(Image.YES)
11 sleep(500)
12 display.clear()
13 elif message == 'no':
14 display.show(Image.NO)
15 sleep(500)
16 display.clear()
17 if button_a.was_pressed():
18 radio.send('yes')
19 display.show(Image.YES)
20 sleep(500)
21 display.clear()
22 if button_b.was_pressed():
23 radio.send('no')
24 display.show(Image.NO)
25 sleep(500)
26 display.clear()
27
Step 3: Improve it
- Show different icons or messages for ‘yes’ and ‘no’.
- Use shake, tilt or buttons A and B together to send different answers such as ‘maybe.’
- Change ‘yes’ and ‘no’ to ‘dot’ and ‘dash’ and send Morse code messages.
This content is published under a Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) licence.