1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
Compass
*******
.. py:module:: microbit.compass
This module lets you access the built-in electronic compass. Before using,
the compass should be calibrated, otherwise the readings may be wrong.
.. warning::
Calibrating the compass will cause your program to pause until calibration
is complete. Calibration consists of a little game to draw a circle on the
LED display by rotating the device.
Functions
=========
.. py:function:: calibrate()
Starts the calibration process. An instructive message will be scrolled
to the user after which they will need to rotate the device in order to
draw a circle on the LED display.
.. py:function:: is_calibrated()
Returns ``True`` if the compass has been successfully calibrated, and
returns ``False`` otherwise.
.. py:function:: clear_calibration()
Undoes the calibration, making the compass uncalibrated again.
.. py:function:: get_x()
Gives the reading of the magnetic field strength on the ``x`` axis in nano
tesla, as a positive or negative integer, depending on the direction of the
field.
.. py:function:: get_y()
Gives the reading of the magnetic field strength on the ``y`` axis in nano
tesla, as a positive or negative integer, depending on the direction of the
field.
.. py:function:: get_z()
Gives the reading of the magnetic field strength on the ``z`` axis in nano
tesla, as a positive or negative integer, depending on the direction of the
field.
.. py:function:: heading()
Gives the compass heading, calculated from the above readings, as an
integer in the range from 0 to 360, representing the angle in degrees,
clockwise, with north as 0.
.. py:function:: get_field_strength()
Returns an integer indication of the magnitude of the magnetic field around
the device in nano tesla.
Example
=======
.. include:: ../examples/compass.py
:code: python
|