on Received Number

Run part of a program when the board receives a number over radio.

radio.onReceivedNumber(function (receivedNumber) {})

Parameters

Watch this video to see how the radio hardware works on the board:

Examples

Tell me how fast

This program keeps sending numbers that say how fast the board is slowing down or speeding up. It also receives numbers for the same thing from nearby boards. It shows these numbers as a bar graph.

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

What’s the distance?

This program uses the signal strength from received packets to graph the approximate distance between two boards.

basic.forever(() => {
    radio.sendNumber(0)
})
radio.onReceivedNumber(function (receivedNumber) {
    led.plotBarGraph(
        Math.abs(radio.receivedPacket(RadioPacketProperty.SignalStrength) + 42),
        128 - 42
    )
})

Troubleshooting

The ||radio:onReceivedNumber|| event can only be created once, due to the hardware restrictions.

The radio set group might need to be set, synchronized, before the radio events will function.

See also

on received string, received packet, send number, send string, send value, set group

radio