1515##
1616
1717import time
18- import math
1918import board
2019import busio
2120import adafruit_lsm9ds1
2221
22+
2323def map_range (x , in_min , in_max , out_min , out_max ):
2424 """
2525 Maps a number from one range to another.
@@ -32,6 +32,7 @@ def map_range(x, in_min, in_max, out_min, out_max):
3232
3333 return min (max (mapped , out_max ), out_min )
3434
35+
3536def calibrate ():
3637 """
3738 Calibrates a magnometer or gyroscope
@@ -67,7 +68,7 @@ def calibrate():
6768 zavg += gz
6869 countavg += 1
6970
70- if ( time .monotonic () - lastDisplayTime >= 3 ) :
71+ if time .monotonic () - lastDisplayTime >= 3 :
7172 print ("Uncalibrated:" , x , y , z )
7273 cal_x = map_range (x , MAG_MIN [0 ], MAG_MAX [0 ], - 1 , 1 )
7374 cal_y = map_range (y , MAG_MIN [1 ], MAG_MAX [1 ], - 1 , 1 )
@@ -78,4 +79,4 @@ def calibrate():
7879 print ("Uncalibrated gyro: " , (gx , gy , gz ))
7980 print ("Gyro: " , (xavg / countavg , yavg / countavg , zavg / countavg ))
8081
81- lastDisplayTime = time .monotonic ()
82+ lastDisplayTime = time .monotonic ()
0 commit comments