pxt-calliope/libs/radio-broadcast/docs/reference/radio/on-received-message.md
Peli de Halleux 6209f0cc63
scratch like broadcast api (#1358)
* scratch like broadcast api

* always register handler

* adding docs

* added icon

* updated block name

* adding DAL support "radio.raiseEvent"

* typo

* implemented using radiobus

* adding docs

* adding raise event block

* updated shims

* updated pxt
2018-10-08 09:46:23 -07:00

976 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.onButtonPressed(Button.A, function () {
    radio.sendMessage(RadioMessage.heart)
})
input.onButtonPressed(Button.B, 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