pxt-calliope/docs/reference/radio/on-data-received.md
Ron Hale-Evans 54331eb113 Second pass
2016-06-02 16:24:06 -07:00

31 lines
850 B
Markdown

# On Data Received
Run part of a program when the micro:bit receives a
[number](/reference/types/number) or [string](/reference/types/string) over ``radio``.
### Parameters
* the part of the program to run when the micro:bit receives information over ``radio``.
### 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](/reference/led/plot-bar-graph).
```blocks
basic.forever(() => {
radio.sendNumber(input.acceleration(Dimension.X));
})
radio.onDataReceived(() => {
led.plotBarGraph(radio.receiveNumber(), 1023);
})
```
### See also
[receive number](/reference/radio/receive-number),
[send number](/reference/radio/send-number), [set group](/reference/radio/set-group)