pxt-calliope/docs/reference/radio/send-string.md

44 lines
894 B
Markdown
Raw Normal View History

2016-05-25 01:53:13 +01:00
# Send String
2016-11-01 17:44:37 -07:00
Sends a string to other @boardname@s in the area connected by radio. The
maximum string length is 19 characters.
2016-05-25 01:53:13 +01:00
```sig
radio.sendString("Hello!")
2016-05-25 01:53:13 +01:00
```
### Parameters
2017-03-16 07:57:41 -07:00
* `msg` is a [string](/types/string) to send by radio.
2016-05-25 01:53:13 +01:00
2016-06-09 15:30:47 -07:00
### Example: Two-way radio
2016-05-25 01:53:13 +01:00
2016-11-01 17:44:37 -07:00
If you load this program onto two or more @boardname@s, you can send a
2016-07-18 14:04:15 -07:00
code word from one of them to the others by pressing button `A`. The
2016-11-01 17:44:37 -07:00
other @boardname@s will receive the code word and then show it.
2016-05-25 01:53:13 +01:00
```blocks
input.onButtonPressed(Button.A, () => {
radio.sendString("Codeword: TRIMARAN")
basic.showString("SENT");
2016-05-25 01:53:13 +01:00
})
radio.onDataPacketReceived(({ receivedString }) => {
basic.showString(receivedString);
});
2016-05-25 01:53:13 +01:00
```
### ~hint
A radio that can both transmit and receive is called a _transceiver_.
### ~
2016-05-25 01:53:13 +01:00
### See also
[on data packet received](/reference/radio/on-data-packet-received)
```package
radio
```