Radiodocsupdate (#1430)
* a few updates * more updates * reorder radio blocks * more shuffling of new radio apis * fixing hot or ocold * more doc fixes * more updates * fixing docs issues * more doc fixes * restore docs errors * missing packate * renamed argument of callback * mssing radio * more odcs fixes * lock turtle * ignore docs for now
This commit is contained in:
58
docs/reference/radio/on-received-buffer.md
Normal file
58
docs/reference/radio/on-received-buffer.md
Normal file
@ -0,0 +1,58 @@
|
||||
# on Received Buffer
|
||||
|
||||
Run part of a program when the @boardname@ receives a buffer over ``radio``.
|
||||
|
||||
```sig
|
||||
radio.onReceivedBuffer(function (receivedBuffer) {})
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
* **receivedBuffer**: The buffer that was sent in this packet or the empty string if this packet did not contain a string. See [send buffer](/reference/radio/send-buffer)
|
||||
|
||||
## Example: Remote level
|
||||
|
||||
If you load this program onto two @boardname@s, each board will send the level information to the other board.
|
||||
|
||||
```typescript
|
||||
let ax = 0;
|
||||
let ay = 0;
|
||||
basic.forever(() => {
|
||||
ax = input.acceleration(Dimension.X);
|
||||
ay = input.acceleration(Dimension.Y);
|
||||
|
||||
// encode data in buffer
|
||||
let buf = pins.createBuffer(4)
|
||||
buf.setNumber(NumberFormat.Int16LE, 0, ax)
|
||||
buf.setNumber(NumberFormat.Int16LE, 2, ay)
|
||||
radio.sendBuffer(buf)
|
||||
})
|
||||
|
||||
radio.onReceivedBuffer(function (receivedBuffer) {
|
||||
// decode data from buffer
|
||||
ax = receivedBuffer.getNumber(NumberFormat.Int16LE, 0);
|
||||
ay = receivedBuffer.getNumber(NumberFormat.Int16LE, 2);
|
||||
|
||||
// display
|
||||
basic.clearScreen()
|
||||
led.plot(
|
||||
pins.map(ax, -1023, 1023, 0, 4),
|
||||
pins.map(ay, -1023, 1023, 0, 4)
|
||||
)
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## ~hint
|
||||
|
||||
A radio that can both transmit and receive is called a _transceiver_.
|
||||
|
||||
## ~
|
||||
|
||||
## See also
|
||||
|
||||
[send buffer](/reference/radio/send-buffer)
|
||||
|
||||
```package
|
||||
radio
|
||||
```
|
Reference in New Issue
Block a user