2016-04-16 01:36:31 +02:00
|
|
|
# Write Value
|
|
|
|
|
2016-07-09 00:29:14 +02:00
|
|
|
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);
|
|
|
|
```
|
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## Parameters
|
2016-07-11 20:13:13 +02:00
|
|
|
|
2017-03-16 15:57:41 +01:00
|
|
|
* `name` is the [string](/types/string) to write to the serial port
|
|
|
|
* `value` is the [number](/types/number) to write to the serial port
|
2016-07-11 20:13:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## Example: streaming data
|
2016-04-16 01:36:31 +02:00
|
|
|
|
2016-07-09 00:29:14 +02:00
|
|
|
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);
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
### ~hint
|
2016-04-16 01:36:31 +02:00
|
|
|
|
2016-07-09 00:29:14 +02:00
|
|
|
The [send value](/reference/radio/send-value) function broadcasts
|
2016-11-02 01:44:37 +01:00
|
|
|
string/number pairs. You can use a second @boardname@ to receive them,
|
2016-07-09 00:29:14 +02:00
|
|
|
and then send them directly to the serial port with ``write value``.
|
2016-04-16 01:36:31 +02:00
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
### ~
|
2016-04-16 01:36:31 +02:00
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## See also
|
2016-04-16 01:36:31 +02:00
|
|
|
|
2016-07-09 00:29:14 +02:00
|
|
|
[serial](/device/serial),
|
|
|
|
[serial write line](/reference/serial/write-line),
|
|
|
|
[serial write number](/reference/serial/write-number),
|
|
|
|
[send value](/reference/radio/send-value)
|