pxt-calliope/docs/reference/serial/write-line.md
Galen Nickel 0ec922c7f4 Fix compass doc errors (#721)
* Fix compass doc errors

* Another heading point error
2018-03-27 15:02:38 -07:00

1.2 KiB

Serial Write Line

Write a string to the serial port and start a new line of text by writing \r\n.

serial.writeLine("");

Parameters

  • text is the string to write to the serial port

Example: simple serial

This program writes the word BOFFO to the serial port repeatedly.

basic.forever(() => {
    serial.writeLine("BOFFO");
    basic.pause(5000);
});

Example: streaming data

This program checks the compass heading and sends the direction to the serial port repeatedly.

let degrees = 0
basic.forever(() => {
    degrees = input.compassHeading()
    if (degrees < 45) {
        basic.showArrow(ArrowNames.North)
    } else if (degrees < 135) {
        basic.showArrow(ArrowNames.East)
    } else if (degrees < 225) {
        basic.showArrow(ArrowNames.South)
    } else if (degrees < 315) {
        basic.showArrow(ArrowNames.West)
    } else {
        basic.showArrow(ArrowNames.North)
    }
})

See also

serial, serial write number, serial write string, serial write value