pxt-calliope/docs/reference/radio/send-value.md
2016-10-24 16:30:21 -07:00

1.1 KiB

Send Value

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

radio.sendValue("data", 0);

Parameters

  • name is a string to send by radio
  • value a number to send by radio

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.onDataPacketReceived(({ text, receivedNumber }) => {
	basic.showString(text);
    basic.showNumber(receivedNumber);
});

See also

on data packet received

radio