2019-12-02 05:58:26 +01:00
|
|
|
# on Received Message
|
|
|
|
|
|
|
|
Run part of a program when the @boardname@ receives a
|
|
|
|
message over ``radio``.
|
|
|
|
|
|
|
|
```sig
|
|
|
|
radio.onReceivedMessage(0, function() {})
|
|
|
|
```
|
|
|
|
|
|
|
|
## Parameters
|
|
|
|
|
|
|
|
* **msg**: The message to listen for. See [send message](/reference/radio/send-message)
|
|
|
|
|
|
|
|
## 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.
|
|
|
|
|
|
|
|
```blocks
|
|
|
|
enum RadioMessage {
|
|
|
|
heart,
|
|
|
|
skull
|
|
|
|
}
|
2023-01-11 18:51:27 +01:00
|
|
|
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), function () {
|
2019-12-02 05:58:26 +01:00
|
|
|
radio.sendMessage(RadioMessage.heart)
|
|
|
|
})
|
2023-01-11 18:51:27 +01:00
|
|
|
input.onButtonEvent(Button.B, input.buttonEventValue(ButtonEvent.Click), function () {
|
2019-12-02 05:58:26 +01:00
|
|
|
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](/reference/radio/send-message),
|
|
|
|
|
|
|
|
```package
|
|
|
|
radio-broadcast
|
|
|
|
```
|