Advertisement
bobbinz

Micro:bit Compass

Oct 27th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Micro:bit Compass
  2. //Adam Robbins 2017
  3.  
  4. //No external components
  5.  
  6. let dir: number
  7.  
  8. basic.forever(() => {
  9.     dir = input.compassHeading()
  10.     if (dir >= 338 || dir < 23 && dir >= 0) {
  11.         basic.showLeds(`
  12.             . . # . .
  13.             . # # # .
  14.             # . # . #
  15.             . . # . .
  16.             . . # . .
  17.             `)
  18.     } else if (dir >= 23 && dir < 68) {
  19.         basic.showLeds(`
  20.             . . # # #
  21.             . . . # #
  22.             . . # . #
  23.             . # . . .
  24.             # . . . .
  25.             `)
  26.     } else if (dir >= 68 && dir < 113) {
  27.         basic.showLeds(`
  28.             . . # . .
  29.             . . . # .
  30.             # # # # #
  31.             . . . # .
  32.             . . # . .
  33.             `)
  34.     } else if (dir >= 113 && dir < 158) {
  35.         basic.showLeds(`
  36.             # . . . .
  37.             . # . . .
  38.             . . # . #
  39.             . . . # #
  40.             . . # # #
  41.             `)
  42.     } else if (dir >= 158 && dir < 203) {
  43.         basic.showLeds(`
  44.             . . # . .
  45.             . . # . .
  46.             # . # . #
  47.             . # # # .
  48.             . . # . .
  49.             `)
  50.     } else if (dir >= 203 && dir < 248) {
  51.         basic.showLeds(`
  52.             . . . . #
  53.             . . . # .
  54.             # . # . .
  55.             # # . . .
  56.             # # # . .
  57.             `)
  58.     } else if (dir >= 248 && dir < 293) {
  59.         basic.showLeds(`
  60.             . . # . .
  61.             . # . . .
  62.             # # # # #
  63.             . # . . .
  64.             . . # . .
  65.             `)
  66.     } else if (dir >= 293 && dir < 338) {
  67.         basic.showLeds(`
  68.             # # # . .
  69.             # # . . .
  70.             # . # . .
  71.             . . . # .
  72.             . . . . #
  73.             `)
  74.     } else {
  75.         basic.showLeds(`
  76.             . . # . .
  77.             . # # # .
  78.             # # . # #
  79.             . # # # .
  80.             . . # . .
  81.             `)
  82.     }
  83. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement