物联网loT从业者物联网相关技术研究物联网之家

Mircopython: 在BPIbit上制作指南针

2019-04-08  本文已影响2人  Janzz

Document

指南针

关于指南针的函数

compass.calibrate()

compass.is_calibrated ()

compass.get_x ()

compass.get_y ()

compass.get_z ()

compass.heading()

compass.get_field_strength()

示例代码

"""
    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])
上一篇下一篇

猜你喜欢

热点阅读