on Received Number

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

radio.onReceivedNumber(function (receivedNumber) {})

Parameters

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

Examples

Tell me how fast

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

radio.setGroup(1)
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 Calliope minis.

radio.setGroup(1)
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