File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ """ Display inclination data five times per second """
2
+
3
+ import time
4
+ import board
5
+ import busio
6
+ import adafruit_lsm303_accel
7
+ from math import atan2 , degrees
8
+
9
+ i2c = busio .I2C (board .SCL , board .SDA )
10
+ sensor = adafruit_lsm303_accel .LSM303_Accel (i2c )
11
+
12
+
13
+ def vector_2_degrees (x , y ):
14
+ radians = atan2 (y , x )
15
+ degrees_calc = degrees (radians )
16
+ if degrees_calc < 0 :
17
+ degrees_calc = 360 + degrees_calc
18
+ return degrees_calc
19
+
20
+
21
+ def get_inclination (_sensor ):
22
+ return get_inclination_respect_x (_sensor ), get_inclination_respect_y (_sensor )
23
+
24
+
25
+ def get_inclination_respect_x (_sensor ):
26
+ accel_axis_data = _sensor .acceleration
27
+ return vector_2_degrees (accel_axis_data [0 ], accel_axis_data [2 ])
28
+
29
+
30
+ def get_inclination_respect_y (_sensor ):
31
+ accel_axis_data = _sensor .acceleration
32
+ return vector_2_degrees (accel_axis_data [1 ], accel_axis_data [2 ])
33
+
34
+
35
+ while True :
36
+ print ("inclination: (%s, %s)" % (get_inclination (sensor )))
37
+ time .sleep (0.2 )
You can’t perform that action at this time.
0 commit comments