pxt-calliope/docs/reference/serial/read-line.md
Sam El-Husseini e3975e65e5 pxt-microbit Accessibility PR ()
* Accessibility changes
2017-09-07 13:42:08 -07:00

846 B

Serial Read Line

Read a line of text from the serial port.

serial.readLine();

~hint

This function expects the line it reads to be terminated with the \r character. If your terminal software does not terminate lines with \r, this function will probably never return a value.

~

Returns

  • a string containing input from the serial port, such as a response typed by a user

Example

The following example requests the user's name, then repeats it to greet the user.

basic.forever(() => {
    serial.writeLine("What is your name?");
    let answer = serial.readLine();
    serial.writeString("Hello,");
    serial.writeLine(answer);
});

See also

serial, serial write line, serial write value