Search code examples
pythonembeddedbbc-microbit

bbc micro bit radio string broadcast


I have some really simple code, which I want to build up to detect button presses and then send out the button status using the radio function. But I cannot get the code to work, I thought setting the string with a fix text and then broadcast using the radio function would just work, but seem to be getting an error. I don't want to do via if states, as I will add more into the string with different sensor values and button presses etc.

from microbit import *
import radio

radio.config(group=0)
radio.on()

while True:

     button_status_a = "Button A pressed"

     radio.send(button_status_a)
     sleep(1000)

Solution

  • You don't say how you are detecting the transmission. There is a working example of sending and receiving simple messages using button presses at this question:

    BBC Bit Micro - Radio string transfer random carriage returns

    The example uses if statements which you say you want to avoid. These are used to detect the button press.