pxt-calliope/libs/radio-broadcast/docs/reference/radio/on-received-message.md
2020-02-20 04:01:37 +01:00

1022 B

on Received Message

Run part of a program when the @boardname@ receives a message over radio.

radio.onReceivedMessage(0, function() {})

Parameters

Examples

Example: Broadcasting heart or skull

Sends a heart message when A is pressed, skull when B is pressed. On the side, display heart or skull for the message.

enum RadioMessage {
    heart,
    skull
}
input.input.onButtonEvent(Button.A, ButtonEvent.Click, function () {
    radio.sendMessage(RadioMessage.heart)
})
input.input.onButtonEvent(Button.B, ButtonEvent.Click, function () {
    radio.sendMessage(RadioMessage.skull)
})
radio.onReceivedMessage(RadioMessage.heart, function () {
    basic.showIcon(IconNames.Heart)
})
radio.onReceivedMessage(RadioMessage.skull, function () {
    basic.showIcon(IconNames.Skull)
})

See also

send message,

radio-broadcast