Created
May 28, 2017 13:47
Star
You must be signed in to star a gist
Compass app for micro:bit which shows where's the NORTH. App reads compassHeading value and uses it to determine which LED to turn on. All 360 degrees are divided by 12 (ie. 30 degrees). 12 LEDs around the LED matrix are used to show the NORTH.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let Angle = 0 | |
basic.forever(() => { | |
Angle = input.compassHeading() | |
if (345 < Angle || Angle < 15) { | |
basic.showLeds(` | |
. . # . . | |
. . . . . | |
. . . . . | |
. . . . . | |
. . . . . | |
`) | |
} else { | |
if (15 < Angle && Angle < 45) { | |
basic.showLeds(` | |
. # . . . | |
. . . . . | |
. . . . . | |
. . . . . | |
. . . . . | |
`) | |
} else { | |
if (45 < Angle && Angle < 75) { | |
basic.showLeds(` | |
. . . . . | |
# . . . . | |
. . . . . | |
. . . . . | |
. . . . . | |
`) | |
} else { | |
if (75 < Angle && Angle < 105) { | |
basic.showLeds(` | |
. . . . . | |
. . . . . | |
# . . . . | |
. . . . . | |
. . . . . | |
`) | |
} else { | |
if (105 < Angle && Angle < 135) { | |
basic.showLeds(` | |
. . . . . | |
. . . . . | |
. . . . . | |
# . . . . | |
. . . . . | |
`) | |
} else { | |
if (135 < Angle && Angle < 165) { | |
basic.showLeds(` | |
. . . . . | |
. . . . . | |
. . . . . | |
. . . . . | |
. # . . . | |
`) | |
} else { | |
if (165 < Angle && Angle < 195) { | |
basic.showLeds(` | |
. . . . . | |
. . . . . | |
. . . . . | |
. . . . . | |
. . # . . | |
`) | |
} else { | |
if (195 < Angle && Angle < 225) { | |
basic.showLeds(` | |
. . . . . | |
. . . . . | |
. . . . . | |
. . . . . | |
. . . # . | |
`) | |
} else { | |
if (225 < Angle && Angle < 255) { | |
basic.showLeds(` | |
. . . . . | |
. . . . . | |
. . . . . | |
. . . . # | |
. . . . . | |
`) | |
} else { | |
if (255 < Angle && Angle < 285) { | |
basic.showLeds(` | |
. . . . . | |
. . . . . | |
. . . . # | |
. . . . . | |
. . . . . | |
`) | |
} else { | |
if (285 < Angle && Angle < 315) { | |
basic.showLeds(` | |
. . . . . | |
. . . . # | |
. . . . . | |
. . . . . | |
. . . . . | |
`) | |
} else { | |
basic.showLeds(` | |
. . . # . | |
. . . . . | |
. . . . . | |
. . . . . | |
. . . . . | |
`) | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment