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

36 lines
854 B
Markdown
Raw Normal View History

2016-04-16 01:36:31 +02:00
# Write Value
Write a name/value pair and a newline character (`\r\n`) to the [serial](/device/serial) port.
2016-04-16 01:36:31 +02:00
```sig
serial.writeValue("x", 0);
```
### Example: streaming data
Every 10 seconds, the example below sends the temperature and light level
to the serial port.
2016-04-16 01:36:31 +02:00
```blocks
basic.forever(() => {
serial.writeValue("temp", input.temperature())
serial.writeValue("light", input.lightLevel())
basic.pause(10000);
})
```
#### ~hint
2016-04-16 01:36:31 +02:00
The [send value](/reference/radio/send-value) function broadcasts
string/number pairs. You can use a second micro:bit to receive them,
and then send them directly to the serial port with ``write value``.
2016-04-16 01:36:31 +02:00
#### ~
2016-04-16 01:36:31 +02:00
### See also
[serial](/device/serial),
[serial write line](/reference/serial/write-line),
[serial write number](/reference/serial/write-number),
[send value](/reference/radio/send-value)