There is a compass on the BBC micro:bit. If you ever make a weather station use the device to work out the wind direction.
CompassIt can also tell you the direction of North like this:
from microbit import * compass.calibrate() while True: needle = ((15 - compass.heading()) // 30) % 12 display.show(Image.ALL_CLOCKS[needle])
Note
You must calibrate the compass before taking readings. Failure to do so will produce garbage results. The calibration
method runs a fun little game to help the device work out where it is in relation to the Earth’s magnetic field.
To calibrate the compass, tilt the micro:bit around until a circle of pixels is drawn on the outside edges of the display.
The program takes the compass.heading
and, using some simple yet cunning maths, floor division //
and modulo %
, works out the number of the clock hand to use to display on the screen so that it is pointing roughly North.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4