pxt-calliope/docs/reference/serial/write-line.md

52 lines
1.0 KiB
Markdown
Raw Normal View History

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("");
```
2016-07-08 20:46:51 +02:00
### Parameters
* `line` is the [string](/reference/types/string) to write to the serial port
### 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);
});
```
2016-04-16 01:36:31 +02:00
### Example: streaming data
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
basic.forever(() => {
let heading = input.compassHeading()
if (heading < 45) {
serial.writeLine("N");
} else if (heading < 135) {
serial.writeLine("E");
}
else if (heading < 225) {
serial.writeLine("S");
}
else {
serial.writeLine("W");
}
})
```
### See also
2016-07-08 20:46:51 +02:00
[serial](/device/serial),
[serial write number](/reference/serial/write-number),
2016-07-08 20:46:51 +02:00
[serial write value](/reference/serial/write-value)