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

63 lines
1.5 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
Write a string to the [serial](/device/serial) port and start a new line of text
2016-07-08 20:46:51 +02:00
by writing `\r\n`.
2016-04-16 01:36:31 +02:00
```sig
serial.writeLine("");
```
## Parameters
2016-07-08 20:46:51 +02:00
* `text` is the [string](/types/string) to write to the serial port
2016-07-08 20:46:51 +02:00
## Examples
2016-07-08 20:46:51 +02:00
### Simple serial
Write the word `BOFFO` to the serial port repeatedly.
2016-07-08 20:46:51 +02:00
```blocks
basic.forever(() => {
serial.writeLine("BOFFO");
basic.pause(5000);
});
```
### Streaming data
2016-04-16 01:36:31 +02:00
Check the [compass heading](/reference/input/compass-heading) and show the direction on the screen. Also, send both the direction and degree heading to the serial port.
2016-04-16 01:36:31 +02:00
```blocks
let degrees = 0
let direction = ""
2016-04-16 01:36:31 +02:00
basic.forever(() => {
degrees = input.compassHeading()
if (degrees < 45) {
basic.showArrow(ArrowNames.North)
direction = "North"
} else if (degrees < 135) {
basic.showArrow(ArrowNames.East)
direction = "East"
} else if (degrees < 225) {
basic.showArrow(ArrowNames.South)
direction = "South"
} else if (degrees < 315) {
basic.showArrow(ArrowNames.West)
direction = "West"
} else {
basic.showArrow(ArrowNames.North)
direction = "North"
2016-04-16 01:36:31 +02:00
}
serial.writeLine(direction + " @ " + degrees + " degrees")
basic.pause(500)
2016-04-16 01:36:31 +02:00
})
```
## See also
2016-04-16 01:36:31 +02:00
2016-07-08 20:46:51 +02:00
[serial](/device/serial),
[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)