a93febb5b7
* add image and deprecated arrow functions * update locales * map basic.showArrow * map arrow blocks * map & remove arrow images * remove arrow blocks * update locales * remove & patch: rgbw -> rgb button/pin pressed -> button/pin event loudness -> soundLevel * update ts mappings for arrows * add wip ts patch rules * update .blocks files * use Click instead of Down as default in Documentation and tests * patch test.blocks * fix lowercase name tag * update test.blocks * update blocks test files * update blocks test files * format block files * pass blocks file tests * fix ts mapping * fix color.defl value closes https://github.com/microsoft/pxt-calliope/issues/136 * fix ts mappings - add optional spacing at the end of rgbw() - map up to v4.0.19 * add suggested changes * replace innerText by textContent Co-authored-by: JW <gitkraken@juriwolf.de> Co-authored-by: Juri <info@juriwolf.de>
98 lines
2.1 KiB
Markdown
98 lines
2.1 KiB
Markdown
# receive String
|
|
|
|
Find the next string sent by radio from another @boardname@.
|
|
|
|
```sig
|
|
radio.receiveString()
|
|
```
|
|
## ~ hint
|
|
|
|
**Deprecated**
|
|
|
|
This API has been deprecated! Use [on received string](/reference/radio/on-received-string) instead.
|
|
|
|
## ~
|
|
|
|
## Returns
|
|
|
|
* the first [string](/types/string) that was sent. If no
|
|
string was sent, then this function returns an empty (blank) string.
|
|
|
|
## Example: Simple receiver
|
|
|
|
Show the string sent by another @boardname@.
|
|
|
|
```blocks
|
|
radio.onDataReceived(() => {
|
|
basic.showString(radio.receiveString());
|
|
});
|
|
```
|
|
|
|
## Example: Two-way radio
|
|
|
|
If you load this program onto two or more @boardname@s, you can send a code word from one of them to the others by pressing button `A`.
|
|
The other @boardname@s will receive the code word and then show it.
|
|
|
|
```blocks
|
|
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
|
radio.sendString("Codeword: TRIMARAN")
|
|
basic.showString("SENT");
|
|
})
|
|
|
|
radio.onDataReceived(() => {
|
|
basic.showString(radio.receiveString());
|
|
});
|
|
```
|
|
|
|
## ~hint
|
|
|
|
A radio that can both transmit and receive is called a _transceiver_.
|
|
|
|
## ~
|
|
|
|
## Example: Mood radio
|
|
|
|
This is a simple program to send whether you are happy or sad over ```radio```.
|
|
Use the `A` or `B` button to select an emotion.
|
|
|
|
This program will also receive your friend's mood.
|
|
|
|
```blocks
|
|
let data: string = "";
|
|
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
|
radio.sendString("H");
|
|
});
|
|
input.onButtonEvent(Button.B, ButtonEvent.Click, () => {
|
|
radio.sendString("S");
|
|
});
|
|
radio.onDataReceived(() => {
|
|
data = radio.receiveString();
|
|
if ("H" == data) {
|
|
basic.showLeds(`
|
|
. . . . .
|
|
. # . # .
|
|
. . . . .
|
|
# . . . #
|
|
. # # # .
|
|
`);
|
|
} else if ("S" == data) {
|
|
basic.showLeds(`
|
|
. . . . .
|
|
. # . # .
|
|
. . . . .
|
|
. # # # .
|
|
# . . . #
|
|
`);
|
|
} else {
|
|
basic.showString("?");
|
|
}
|
|
});
|
|
```
|
|
|
|
## See also
|
|
|
|
[send string](/reference/radio/send-string), [on data received](/reference/radio/on-data-received)
|
|
|
|
```package
|
|
radio
|
|
``` |