You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
857 B

#2022 Jamie Munro
from microbit import *
import radio
CONTROL_CHAR = "*"
RADIO_GROUP = 222
RADIO_CHANNEL = 5
RADIO_LENGTH = 36
MSG_LENGTH = RADIO_LENGTH - 3
DELAY = 0
def setup():
print("Starting...")
print("Turning radio on...")
radio.on()
radio.config(group=RADIO_GROUP, channel=RADIO_CHANNEL, length=RADIO_LENGTH)
while True:
loop()
sleep(DELAY)
def loop():
#get message from buffer
incoming = radio.receive()
#perform a bunch of sanity checks to insure this is a valid message
#TODO: investigate performance impact of sanity checks, maybe this should be done at app level
#TODO: investigate performance speed up of direct byte encoding instead of string manipulation
if incoming != None and incoming[0] == CONTROL_CHAR and len(incoming) == MSG_LENGTH:
print(incoming)
setup()