Treasure Hunt with a MicroBit – Using Radio

This is the MicroBit. It is a delightful and easy to use microprocessor that can introduce beginners to a simple programming.  It has some built in LEDs, buttons, and sensors, all for about $15. 
Using two or more devices, I decided to make a Treasure Hunting game.  In this game, a Treasure Hunter has a MicroBit, and walks up to different Sign Posts(which are also MicroBits).  The Treasure Hunter presses a button, and the Sign Post gives directions.  The Treasure Hunter follows the directions to the next Sign Post until they reach the treasure.

There are two versions of the game, that are made to highlight the send and receive functions of the MicroBits.

Version One:  The Sign Posts show the directions.

Version Two: The Sign Posts transmit the directions back to the Treasure Hunter.

The code for each version is below:

Version One – Sign Post

Version One Treasure Hunter

Version Two Sign Post

from microbit import *
import radio

radio.on()
radio.config(channel=10)
radio.config(power=7)

direction = "GO RIGHT"
steps = "20 PACES"

while True:
  incoming=radio.receive()
  if incoming is not None:
    display.scroll("SENT") # shows that a message was sent
    radio.send(direction)
    sleep(1000)
    radio.send(steps)

Version Two Treasure Hunter


from microbit import *
import radio

radio.on() #turn on the radio
radio.config(channel=10)
radio.config(power=7)

message = "TEST"

while True:
  incoming=radio.receive()
  if button_a.is_pressed():
    radio.send(message)
    display.scroll("Sent")
  if incoming is not None:
    display.scroll(incoming)

 

Leave a Reply

Your email address will not be published. Required fields are marked *