* update yotta defaults for 16kb devices * refactor deprecated blocks * updates for button events * update button events * update refference * update docs * update docs * update button event blocks * update docs * update block id
1.9 KiB
on Received Number
Run part of a program when the @boardname@ receives a
number over radio
.
radio.onReceivedNumber(function (receivedNumber) {})
Parameters
- receivedNumber: The number that was sent in this packet or
0
if this packet did not contain a number. See send number and send value
~ hint
Watch this video to see how the radio hardware works on the @boardname@:
https://www.youtube.com/watch?v=Re3H2ISfQE8
~
Examples
Tell me how fast
This program keeps sending numbers that say 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.
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 @boardname@s.
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