fixed compass error

Compass example has error in direction detect. It will get wrong result if you write it to micro:bit.

And I also fixed degree between 315-359.
This commit is contained in:
shaoziyang 2017-09-08 00:12:55 +08:00 committed by GitHub
parent b6c778065f
commit 3fe18bc5fb

View File

@ -37,15 +37,20 @@ that means whether the @boardname@ is facing north (N), south (S),
east (E), or west (W). east (E), or west (W).
```blocks ```blocks
let degrees = 0
basic.forever(() => { basic.forever(() => {
let degrees = input.compassHeading() degrees = input.compassHeading()
if (degrees < 45) if (degrees < 45) {
basic.showString("N") basic.showArrow(ArrowNames.North)
else if (degrees < 135) } else if (degrees < 135) {
basic.showString("E") basic.showArrow(ArrowNames.West)
else if (degrees < 225) } else if (degrees < 225) {
basic.showString("S") basic.showArrow(ArrowNames.South)
else basic.showString("W") } else if (degrees < 315) {
basic.showArrow(ArrowNames.East)
} else {
basic.showArrow(ArrowNames.North)
}
}) })
``` ```