Updates for V4 (#197)
* update yotta defaults for 16kb devices * refactor deprecated blocks * updates for button events * update button events * update refference * update docs * update docs * update button event blocks * update docs * update block id
This commit is contained in:
@ -9,17 +9,19 @@ serial.readBuffer(64);
|
||||
## Parameters
|
||||
|
||||
* **length**: the [number](/types/number) of characters of serial data to read.
|
||||
Use ``0`` to return the available buffered data.
|
||||
|
||||
## Returns
|
||||
|
||||
* a [buffer](/types/buffer) containing input from the serial port. The length of the buffer may be smaller than the requested length.
|
||||
The length is 0 if any error occurs.
|
||||
|
||||
## ~hint
|
||||
**Pause for more data**
|
||||
|
||||
If the desired number of characters are available, **readBuffer** returns a buffer with the expected size. If not, the calling fiber (the part of your program calling the **readBuffer** function) sleeps until the desired number of characters are finally read into the buffer.
|
||||
|
||||
The need to pause for more data is set by the @boardname@ **[serial mode](https://lancaster-university.github.io/microbit-docs/ubit/serial/#serial-modes)**.
|
||||
To avoid waiting for data, set the length to ``0`` so that buffered data is returned immediately.
|
||||
## ~
|
||||
|
||||
## Example
|
||||
@ -27,13 +29,27 @@ The need to pause for more data is set by the @boardname@ **[serial mode](https:
|
||||
Read character data from the serial port one row at a time. Write the rows to an LED display connected to the I2C pins.
|
||||
|
||||
```typescript
|
||||
let rowData: Buffer = null;
|
||||
serial.setRxBufferSize(10)
|
||||
for (let i = 0; i < 24; i++) {
|
||||
rowData = serial.readBuffer(80);
|
||||
let rowData = serial.readBuffer(10);
|
||||
pins.i2cWriteBuffer(65, rowData, false);
|
||||
}
|
||||
```
|
||||
|
||||
## Example Async
|
||||
|
||||
Read available data and process it as it comes.
|
||||
|
||||
```typescript
|
||||
basic.forever(function() {
|
||||
let rowData = serial.readBuffer(0);
|
||||
if (rowData.length > 0) {
|
||||
// do something!!!
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
## See Also
|
||||
|
||||
[write buffer](/reference/serial/write-buffer)
|
||||
|
Reference in New Issue
Block a user