Login

Please fill in your details to login.





micro:bit - compass

This page is mainly about micro:bit - compass
"""
  compass.py
  ~~~~~~~~~~
  Creates a compass.

  The user will need to calibrate the compass first. The compass uses the
  built-in clock images to display the position of the needle.

"""
from microbit import *

# Start calibrating
compass.calibrate()

# Try to keep the needle pointed in (roughly) the correct direction
while True:
  sleep(100)
  needle = ((15 - compass.heading()) // 30) % 12
  display.show(Image.ALL_CLOCKS[needle])

Last modified: October 5th, 2021
The Computing Café works best in landscape mode.
Rotate your device.
Dismiss Warning