Put 'writeLine' into serial ref example (#1747)
* Put 'writeLine' into serial ref example * how about a space
This commit is contained in:
parent
3eb46f08a4
commit
f4bb37b4bf
@ -11,9 +11,11 @@ serial.writeLine("");
|
|||||||
|
|
||||||
* `text` is the [string](/types/string) to write to the serial port
|
* `text` is the [string](/types/string) to write to the serial port
|
||||||
|
|
||||||
## Example: simple serial
|
## Examples
|
||||||
|
|
||||||
This program writes the word `BOFFO` to the serial port repeatedly.
|
### Simple serial
|
||||||
|
|
||||||
|
Write the word `BOFFO` to the serial port repeatedly.
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
basic.forever(() => {
|
basic.forever(() => {
|
||||||
@ -22,29 +24,36 @@ basic.forever(() => {
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
## Example: streaming data
|
### Streaming data
|
||||||
|
|
||||||
This program checks the
|
Check the [compass heading](/reference/input/compass-heading) and show the direction on the screen. Also, send both the direction and degree heading to the serial port.
|
||||||
[compass heading](/reference/input/compass-heading) and sends the
|
|
||||||
direction to the serial port repeatedly.
|
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
let degrees = 0
|
let degrees = 0
|
||||||
|
let direction = ""
|
||||||
basic.forever(() => {
|
basic.forever(() => {
|
||||||
degrees = input.compassHeading()
|
degrees = input.compassHeading()
|
||||||
if (degrees < 45) {
|
if (degrees < 45) {
|
||||||
basic.showArrow(ArrowNames.North)
|
basic.showArrow(ArrowNames.North)
|
||||||
|
direction = "North"
|
||||||
} else if (degrees < 135) {
|
} else if (degrees < 135) {
|
||||||
basic.showArrow(ArrowNames.East)
|
basic.showArrow(ArrowNames.East)
|
||||||
|
direction = "East"
|
||||||
} else if (degrees < 225) {
|
} else if (degrees < 225) {
|
||||||
basic.showArrow(ArrowNames.South)
|
basic.showArrow(ArrowNames.South)
|
||||||
|
direction = "South"
|
||||||
} else if (degrees < 315) {
|
} else if (degrees < 315) {
|
||||||
basic.showArrow(ArrowNames.West)
|
basic.showArrow(ArrowNames.West)
|
||||||
|
direction = "West"
|
||||||
} else {
|
} else {
|
||||||
basic.showArrow(ArrowNames.North)
|
basic.showArrow(ArrowNames.North)
|
||||||
|
direction = "North"
|
||||||
}
|
}
|
||||||
|
serial.writeLine(direction + " @ " + degrees + " degrees")
|
||||||
|
basic.pause(500)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
## See also
|
## See also
|
||||||
|
|
||||||
[serial](/device/serial),
|
[serial](/device/serial),
|
||||||
|
Loading…
Reference in New Issue
Block a user