Micro-bit Network Skills

Micro-bits Skills

  1. Sending and receiving messages
  2. Using Channels to send and receive messages to and from different micro-bits.

Skill One: Sending and receiving messages

Code for micro-bit ONE

from microbit import *
import radio

radio.on()
radio.send("Hi!")

Code for micro-bit TWO

from microbit import *
import radio

radio.on()
radio.send("Hi!")

Skill Two: Using Channels

Using Channels to send and receive messages to and from different micro-bits.

Code for micro-bit ONE

from microbit import *
import radio

radio.on()
while True:
	if button_a.was_pressed():
	  radio.config(channel=12)
		radio.send('TWO')
	if button_b.was_pressed():
	  radio.config(channel=12)
		radio.send('THREE')

Code for micro-bit TWO

from microbit import *
import radio

radio.on()
radio.config(channel=12)

while True:
	message = radio.receive()
		if message:
			display.scroll(message)

Code for micro-bit THREE: Use the same code for micro-bit TWO, just change the channel to 13

Skill Three: Routing messages

Send message from micro-bit ONE to the WAP and the WAP uses a routing table to send the message to the correct micro-bit

Code for micro-bit ONE

from microbit import *
import radio

radio.on()
radio.config(channel=10)
while True:
	if button_a.was_pressed():
		radio.send('TWO:hey')
	if button_b.was_pressed():
		radio.send('THREE:hey')

Code for Router micro-bit

from microbit import *
import radio

radio.on()
radio.config(channel=10)
while True:
	message = radio.receive()
	if message:
		destination, msg = message.split(':')
		
		if destination = “TWO”:
			radio.config(channel=12)
		if destination = “THREE”:
			radio.config(channel=13)
		radio.send(msg)

Code for the two receiver micro-bits:
NOTE: Change the channel to suit the receiver micro-bit

from microbit import *
import radio

radio.on()
radio.config(channel=12)

while True:
	message = radio.receive()
		if message:
			display.scroll(message)