pxt-calliope/docs/reference/radio/on-data-received.md
Sam El-Husseini e3975e65e5 pxt-microbit Accessibility PR ()
* Accessibility changes
2017-09-07 13:42:08 -07:00

932 B

On Data Received

Note: This API has been deprecated! Use on data packet received instead.

Run part of a program when the @boardname@ receives a number or string over radio.

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

Example

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

on data packet received, send number, set group

radio