pxt-calliope/docs/reference/radio/on-data-received.md
Ron Hale-Evans 2c6f76e1a5 First pass
2016-06-02 12:52:03 -07:00

883 B

On Data Received

Run part of a program when the micro:bit receives a number or string over radio.

Parameters

  • body is the part of the program to run when the micro:bit receives information over radio.

Example

This program never stops. It keeps sending numbers that says how fast the micro:bit is slowing down or speeding up. It also receives numbers that say how fast nearby micro:bits are going. It shows these numbers as a bar graph.

basic.forever(() => {
    radio.sendNumber(input.acceleration(Dimension.X));
})
radio.onDataReceived(() => {
    led.plotBarGraph(radio.receiveNumber(), 1023);
})

See also

receive number, send number, set group