pxt-calliope/docs/reference/radio/on-data-received.md
Peli de Halleux bd1536132d fixing references / snippets
cleanup "snippets" compilation state
2016-10-22 21:29:31 -07:00

886 B

On Data Received

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

radio.onDataReceived(() => { });

Simulator

This function only works on the micro:bit, not in browsers.

Example

This program keeps sending numbers that says how fast the micro:bit is slowing down or speeding up. It also receives numbers for the same thing from nearby micro:bits. 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

radio