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

1008 B

Write Value

Write a name/value pair and a newline character (\r\n) to the serial port.

serial.writeValue("x", 0);

Parameters

  • name is the string to write to the serial port
  • value is the number to write to the serial port

Example: streaming data

Every 10 seconds, the example below sends the temperature and light level to the serial port.

basic.forever(() => {
    serial.writeValue("temp", input.temperature())
    serial.writeValue("light", input.lightLevel())
    basic.pause(10000);
})

~hint

The send value function broadcasts string/number pairs. You can use a second @boardname@ to receive them, and then send them directly to the serial port with write value.

~

See also

serial, serial write line, serial write number, send value