You will need:
- 2 or more micro:bits with battery packs
- a computer with which to program them
- optional: headphones or micro:bit speakers
You can hide as many beacons as you want. Using Mu or the online Python editor you put the following Python program on the beacons, changing the ID number so each is unique. Beacons constantly transmit their ID numbers as a string and show their ID number on their displays:
from microbit import * import radio id = "1" display.show(id) radio.config(power=0) # low power so you must get close radio.on() while True: radio.send(id)
In the very simplest version of this game (which should work with the online Python editor or current releases of the Mu Python editor) the players use the following program. This displays an X until a signal is received from a beacon – it should show the beacon’s number for half a second every time it gets a signal. Even though the beacon is set to transmit on low power, it will still get a signal if you are a metre or two away, so this is best played over a large area:
from microbit import * import radio radio.on() while True: message=radio.receive() display.show(Image.NO) if message: display.show(message) sleep(500)
Players should see how many beacons they can find in an allotted time. This simple player code doesn’t log them, it just relies on memory and trust!
WORK IN PROGRESS: More sophisticated versions of player code showing signal strength below require Beta version of Mu 1.0.0 beta 15 or higher
This next version of the player code ignores the ID but displays a number from 1 to 5 showing how strong the signal is. X means no signal received. You could use this to play the game in a smaller area, and you could still use multiple beacons but their IDs are not shown to the player – until they find the beacon of course, when they can read its own display!
from microbit import * import radio radio.on() while True: message=radio.receive_full() if message: strength = message+100 displaystrength = (int((strength/10)+1)) display.show(str(displaystrength)) sleep(200) else: display.show(Image.NO)
Now to be a bit more like a metal detector, it would be nice to have some audio feedback. This next program will play a short note when it receives a signal. The stronger the signal, the higher the pitch, so you can use this to find the beacon.
Attach a micro:bit speaker to the GND and 0 pins. CAUTION: if you attach normal headphones DO NOT WEAR THEM, just put them round your neck just like Lance and Andy in the photo at the top of this page – the sound is very loud. Or put a 3K ohm resistor between pin 0 and the headphones.. You could have some fun making a ‘metal detector’ as I did in the picture above with an old broom handle and some rubber bands.
Here’s the program for the noisy version. As before, this currently needs a beta version of Mu to flash this to your microbits.
from microbit import * import radio,music radio.on() while True: message=radio.receive_full() if message: strength = message+100 displaystrength = (int((strength/10)+1)) display.show(str(displaystrength)) music.pitch(strength*50,100) else: display.show(Image.NO)
If you try this out and have ideas for improvements, please let me know!
- Add logging of beacon numbers and some visual feedback on players’ micro:bits when all beacons found.