指南针的方向

指南针的方向的说明

[指南针的方向插]的图例

../../../_images/compass.heading.png

功能:用来获取当前指南针的角度,返回值为当前的相对角度。

[指南针的方向插]的动画

../../../_images/compass.headings.gif

指南针的方向例程

自制指南针

动手DIY制作一个指南针。此DIY需要使用指南针的方向插和 显示图像拼 和配合 内置图像插 配合完成。

拼插源码

../../../_images/compass.headings.png

实例源码:

from microbit import *

while True:
        if compass.heading() > 0 and compass.heading() <= 90:
                display.show(Image.ARROW_N)
        if compass.heading() > 90 and compass.heading() <= 180:
                display.show(Image.ARROW_E)
        if compass.heading() > 180 and compass.heading() <= 270:
                display.show(Image.ARROW_S)
        if compass.heading() > 270 and compass.heading() <= 360:
                display.show(Image.ARROW_W)