Advertisement
earlution

microbit_compass

May 24th, 2023
608
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. """
  2.    compass.py
  3.    ~~~~~~~~~~
  4.  
  5.    Creates a compass.
  6.  
  7.    The user will need to calibrate the compass first. The compass uses the
  8.    built-in clock images to display the position of the needle.
  9.  
  10.     source: https://microbit-micropython.readthedocs.io/en/latest/compass.html
  11.  
  12. """
  13. from microbit import *
  14.  
  15.  
  16. # Start calibrating
  17. compass.calibrate()
  18.  
  19. # Try to keep the needle pointed in (roughly) the correct direction
  20. while True:
  21.     sleep(100)
  22.     needle = ((15 - compass.heading()) // 30) % 12
  23.     display.show(Image.ALL_CLOCKS[needle])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement