from microbit import * # simple compass # compass.heading() measures magnetic field # taken from page 69 of BBC Micro:bit MicroPython PDF (August 2016) # from https://media.readthedocs.org/pdf/microbit-micropython/latest/microbit-micropython.pdf # creates a simple compass - it starts with a calibration 'game' first then goes # on to the rest of the program # start calibration compass.calibrate() # tries to keep the needle pointing in the roughly correct direction while True: sleep (100) needle = ((15 - compass.heading()) // 30) % 12 display.show (Image.ALL_CLOCKS[needle])