2016-07-08 20:46:51 +02:00
|
|
|
# Serial Write Line
|
2016-04-16 01:36:31 +02:00
|
|
|
|
2016-07-08 20:46:51 +02:00
|
|
|
Write a string to the [serial](/device/serial) port and start a new line of text
|
|
|
|
by writing `\r\n`.
|
2016-04-16 01:36:31 +02:00
|
|
|
|
|
|
|
```sig
|
|
|
|
serial.writeLine("");
|
|
|
|
```
|
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## Parameters
|
2016-07-08 20:46:51 +02:00
|
|
|
|
2017-03-16 15:57:41 +01:00
|
|
|
* `text` is the [string](/types/string) to write to the serial port
|
2016-07-08 20:46:51 +02:00
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## Example: simple serial
|
2016-07-08 20:46:51 +02:00
|
|
|
|
|
|
|
This program writes the word `BOFFO` to the serial port repeatedly.
|
|
|
|
|
|
|
|
```blocks
|
|
|
|
basic.forever(() => {
|
|
|
|
serial.writeLine("BOFFO");
|
|
|
|
basic.pause(5000);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## Example: streaming data
|
2016-04-16 01:36:31 +02:00
|
|
|
|
2016-07-08 20:46:51 +02:00
|
|
|
This program checks the
|
|
|
|
[compass heading](/reference/input/compass-heading) and sends the
|
|
|
|
direction to the serial port repeatedly.
|
2016-04-16 01:36:31 +02:00
|
|
|
|
|
|
|
```blocks
|
2017-09-11 13:22:10 +02:00
|
|
|
let degrees = 0
|
2016-04-16 01:36:31 +02:00
|
|
|
basic.forever(() => {
|
2017-09-11 13:22:10 +02:00
|
|
|
degrees = input.compassHeading()
|
|
|
|
if (degrees < 45) {
|
|
|
|
basic.showArrow(ArrowNames.North)
|
|
|
|
} else if (degrees < 135) {
|
2018-03-28 00:02:38 +02:00
|
|
|
basic.showArrow(ArrowNames.East)
|
2017-09-11 13:22:10 +02:00
|
|
|
} else if (degrees < 225) {
|
|
|
|
basic.showArrow(ArrowNames.South)
|
|
|
|
} else if (degrees < 315) {
|
2018-03-28 00:02:38 +02:00
|
|
|
basic.showArrow(ArrowNames.West)
|
2017-09-11 13:22:10 +02:00
|
|
|
} else {
|
|
|
|
basic.showArrow(ArrowNames.North)
|
2016-04-16 01:36:31 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
```
|
2017-09-07 22:42:08 +02:00
|
|
|
## See also
|
2016-04-16 01:36:31 +02:00
|
|
|
|
2016-07-08 20:46:51 +02:00
|
|
|
[serial](/device/serial),
|
2016-07-09 00:29:14 +02:00
|
|
|
[serial write number](/reference/serial/write-number),
|
2016-07-11 20:13:13 +02:00
|
|
|
[serial write string](/reference/serial/write-string),
|
2016-07-08 20:46:51 +02:00
|
|
|
[serial write value](/reference/serial/write-value)
|