micro:bit radio
Watch this video to see how the radio hardware works on the micro:bit:
Run part of a program when the micro:bit receives a
number over radio
.
radio.onReceivedNumber(function (receivedNumber) {})
0
if this packet did not contain a number. See send number and send valueWatch this video to see how the radio hardware works on the micro:bit:
This program keeps sending numbers that say 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.
radio.setGroup(1)
basic.forever(() => {
radio.sendNumber(input.acceleration(Dimension.X));
})
radio.onReceivedNumber(function (receivedNumber) {
led.plotBarGraph(receivedNumber, 1023);
})
This program uses the signal strength from received packets to graph the approximate distance between two micro:bits.
radio.setGroup(1)
basic.forever(() => {
radio.sendNumber(0)
})
radio.onReceivedNumber(function (receivedNumber) {
led.plotBarGraph(
Math.abs(radio.receivedPacket(RadioPacketProperty.SignalStrength) + 42),
128 - 42
)
})
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.
on received string, received packet, send number, send string, send value, set group
radio