本文整理汇总了Python中astro_pi.AstroPi.get_compass方法的典型用法代码示例。如果您正苦于以下问题:Python AstroPi.get_compass方法的具体用法?Python AstroPi.get_compass怎么用?Python AstroPi.get_compass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类astro_pi.AstroPi
的用法示例。
在下文中一共展示了AstroPi.get_compass方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AstroPi
# 需要导入模块: from astro_pi import AstroPi [as 别名]
# 或者: from astro_pi.AstroPi import get_compass [as 别名]
# The calibration program will produce the file RTIMULib.ini
# Copy it into the same folder as your Python code
led_loop = [4, 5, 6, 7, 15, 23, 31, 39, 47, 55, 63, 62, 61, 60, 59, 58, 57, 56, 48, 40, 32, 24, 16, 8, 0, 1, 2, 3]
ap = AstroPi()
ap.set_rotation(0)
ap.clear()
prev_x = 0
prev_y = 0
led_degree_ratio = len(led_loop) / 360.0
while True:
dir = ap.get_compass()
dir_inverted = 360 - dir # So LED appears to follow North
led_index = int(led_degree_ratio * dir_inverted)
offset = led_loop[led_index]
y = offset // 8 # row
x = offset % 8 # column
if x != prev_x or y != prev_y:
ap.set_pixel(prev_x, prev_y, 0, 0, 0)
ap.set_pixel(x, y, 0, 0, 255)
prev_x = x
prev_y = y