From 3fe18bc5fb3d4ddc7dc54aee94e00013b20c4f99 Mon Sep 17 00:00:00 2001 From: shaoziyang Date: Fri, 8 Sep 2017 00:12:55 +0800 Subject: [PATCH] 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. --- docs/reference/input/compass-heading.md | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/docs/reference/input/compass-heading.md b/docs/reference/input/compass-heading.md index ff76581b..a090fc66 100644 --- a/docs/reference/input/compass-heading.md +++ b/docs/reference/input/compass-heading.md @@ -37,15 +37,20 @@ that means whether the @boardname@ is facing north (N), south (S), east (E), or west (W). ```blocks +let degrees = 0 basic.forever(() => { - let degrees = input.compassHeading() - if (degrees < 45) - basic.showString("N") - else if (degrees < 135) - basic.showString("E") - else if (degrees < 225) - basic.showString("S") - else basic.showString("W") + degrees = input.compassHeading() + if (degrees < 45) { + basic.showArrow(ArrowNames.North) + } else if (degrees < 135) { + basic.showArrow(ArrowNames.West) + } else if (degrees < 225) { + basic.showArrow(ArrowNames.South) + } else if (degrees < 315) { + basic.showArrow(ArrowNames.East) + } else { + basic.showArrow(ArrowNames.North) + } }) ```