2.1.28, initiation update to PXT v5.28.24 (#54)
This commit is contained in:
committed by
Peli de Halleux
parent
38a964516e
commit
5c114a0c57
@ -1,45 +1,42 @@
|
||||
# On Data Packet Received
|
||||
|
||||
Run part of a program when the @boardname@ receives a
|
||||
[number](/reference/types/number) or [string](/reference/types/string) over ``radio``.
|
||||
[number](/types/number) or [string](/types/string) over radio.
|
||||
|
||||
## ~ hint
|
||||
|
||||
```sig
|
||||
radio.onDataPacketReceived(({receivedNumber, receivedString, time, serial, signal}) => { });
|
||||
```
|
||||
**Deprecated**
|
||||
|
||||
### ~hint
|
||||
This API has been deprecated!
|
||||
|
||||
* To receive a [string](/types/string) use [on received string](/reference/radio/on-received-string) instead.
|
||||
* To receive a [number](/types/number) use [on received number](/reference/radio/on-received-number) instead.
|
||||
* To receive a name-value pair use [on received value](/reference/radio/on-received-value) instead.
|
||||
|
||||
## ~
|
||||
|
||||
## ~hint
|
||||
|
||||
To add or remove the parts of the packet from the block, try clicking the blue gear in the corner!
|
||||
|
||||
### ~
|
||||
## ~
|
||||
|
||||
### Callback Parameters
|
||||
## Callback Parameters
|
||||
|
||||
* ``packet`` - the [packet](/reference/radio/packet) that was received by the radio. The packet has the following properties:
|
||||
* `receivedNumber` - The [number](/reference/types/number) that was sent in this packet or `0` if this packet did not contain a number. See [send number](/reference/radio/send-number) and [send value](/reference/radio/send-value)
|
||||
* `receivedString` - The [string](/reference/types/string) that was sent in this packet or the empty string if this packet did not contain a string. See [send string](/reference/radio/send-string) and [send value](/reference/radio/send-value)
|
||||
* `receivedNumber` - The [number](/types/number) that was sent in this packet or `0` if this packet did not contain a number. See [send number](/reference/radio/send-number) and [send value](/reference/radio/send-value)
|
||||
* `receivedString` - The [string](/types/string) that was sent in this packet or the empty string if this packet did not contain a string. See [send string](/reference/radio/send-string) and [send value](/reference/radio/send-value)
|
||||
* `time` - The system time of the @boardname@ that sent this packet at the time the packet was sent.
|
||||
* `serial` - The serial number of the @boardname@ that sent this packet or `0` if the @boardname@ did not include its serial number.
|
||||
* `signal` - How strong the radio signal is from `255` (weak) to `0` (strong).
|
||||
* `signal` - How strong the radio signal is from `-128` (weak) to `-42` (strong).
|
||||
|
||||
### Example
|
||||
## Troubleshooting
|
||||
|
||||
This program keeps sending numbers that says how fast the @boardname@ is
|
||||
slowing down or speeding up. It also receives numbers for the same
|
||||
thing from nearby @boardname@s. It shows these numbers as a
|
||||
[bar graph](/reference/led/plot-bar-graph).
|
||||
The on radio data event can only be created once, due to the hardware restrictions.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
radio.sendNumber(input.acceleration(Dimension.X));
|
||||
})
|
||||
radio.onDataPacketReceived(({ receivedNumber }) => {
|
||||
led.plotBarGraph(receivedNumber, 1023);
|
||||
})
|
||||
```
|
||||
The radio set group might need to be set, synchronized , before the radio events will function.
|
||||
|
||||
### See also
|
||||
## See also
|
||||
|
||||
[send number](/reference/radio/send-number),
|
||||
[send string](/reference/radio/send-string),
|
||||
@ -48,4 +45,4 @@ radio.onDataPacketReceived(({ receivedNumber }) => {
|
||||
|
||||
```package
|
||||
radio
|
||||
```
|
||||
```
|
||||
|
Reference in New Issue
Block a user