本文整理匯總了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