2016-06-17 00:15:14 +02:00
|
|
|
# Send Value
|
2016-06-15 14:09:40 +02:00
|
|
|
|
2016-06-17 00:15:14 +02:00
|
|
|
Send a [string]() and [number]() together by ``radio`` to other micro:bits.
|
2016-10-25 01:30:21 +02:00
|
|
|
The maximum [string]() length is 12 characters.
|
2016-06-15 14:09:40 +02:00
|
|
|
|
2016-07-18 23:04:15 +02:00
|
|
|
```sig
|
|
|
|
radio.sendValue("data", 0);
|
|
|
|
```
|
|
|
|
|
2016-06-15 14:09:40 +02:00
|
|
|
### Parameters
|
|
|
|
|
2016-07-18 23:04:15 +02:00
|
|
|
* ``name`` is a [string](/reference/types/string) to send by radio
|
|
|
|
* ``value`` a [number](/reference/types/number) to send by radio
|
2016-06-15 14:09:40 +02:00
|
|
|
|
|
|
|
### Example: Broadcasting acceleration
|
|
|
|
|
2016-06-17 00:15:14 +02:00
|
|
|
This program sends your micro:bit's **acceleration** (amount it is
|
|
|
|
speeding up or slowing down) in the `x` direction (left and right) to
|
|
|
|
other micro:bits. This kind of program might be useful in a model car
|
|
|
|
or model rocket.
|
2016-06-15 14:09:40 +02:00
|
|
|
|
|
|
|
```blocks
|
2016-06-17 00:33:35 +02:00
|
|
|
radio.setGroup(99)
|
2016-06-15 14:09:40 +02:00
|
|
|
input.onButtonPressed(Button.A, () => {
|
2016-10-26 01:39:13 +02:00
|
|
|
radio.sendValue("acc", input.acceleration(Dimension.X))
|
2016-06-15 14:09:40 +02:00
|
|
|
})
|
|
|
|
```
|
|
|
|
|
2016-06-17 00:15:14 +02:00
|
|
|
This program receives the string and number sent by the last program.
|
|
|
|
Then it shows them on the LED screen.
|
|
|
|
|
|
|
|
```blocks
|
2016-06-17 00:33:35 +02:00
|
|
|
radio.setGroup(99)
|
2016-10-26 01:39:13 +02:00
|
|
|
radio.onDataPacketReceived(({ receivedString, receivedNumber }) => {
|
|
|
|
basic.showString(receivedString);
|
2016-10-25 01:30:21 +02:00
|
|
|
basic.showNumber(receivedNumber);
|
2016-06-17 00:15:14 +02:00
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2016-06-15 14:09:40 +02:00
|
|
|
### See also
|
|
|
|
|
2016-10-25 01:30:21 +02:00
|
|
|
[on data packet received](/reference/radio/on-data-packet-received)
|
2016-06-15 14:09:40 +02:00
|
|
|
|
2016-08-09 17:28:08 +02:00
|
|
|
```package
|
2016-10-23 06:29:31 +02:00
|
|
|
radio
|
2016-08-09 17:28:08 +02:00
|
|
|
```
|