send Value

Send a string and number together by radio to other micro:bits. The maximum string length is 8 characters.

radio.sendValue("name", 0);

Parameters

  • name: a string that is the name of the value to send.
  • value: a number that is the value to send.

Watch this video to see how the radio hardware works on the micro:bit:

Example: Broadcasting acceleration

This program sends your micro:bit’s acceleration (amount it is speeding up or slowing down) in the x direction (left and right) to other micro:bits. This kind of program might be useful in a model car or model rocket.

radio.setGroup(99)
input.onButtonPressed(Button.A, () => {
    radio.sendValue("acc", input.acceleration(Dimension.X))
})

This program receives the string and number sent by the last program. Then it shows them on the LED screen.

radio.setGroup(99)
radio.onReceivedValue(function (name, value) {
    basic.showString(name);
    basic.showNumber(value);
});

See also

on received value

radio