-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestLIS3DH.py
36 lines (28 loc) · 886 Bytes
/
testLIS3DH.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/python
from LIS3DH import LIS3DH
from time import sleep
def clickcallback(channel):
# interrupt handler callback
print "Interrupt detected"
click = sensor.getClick()
print "Click detected (0x%2X)" % (click)
if (click & 0x10): print " single click"
if (click & 0x20): print " double click"
if __name__ == '__main__':
sensor = LIS3DH(debug=True)
sensor.setRange(LIS3DH.RANGE_2G)
sensor.setClick(LIS3DH.CLK_SINGLE,80,mycallback=clickcallback)
print "Starting stream"
while True:
x = sensor.getX()
y = sensor.getY()
z = sensor.getZ()
# raw values
print "\rX: %.6f\tY: %.6f\tZ: %.6f" % (x,y,z)
sleep(0.1)
# click sensor if polling & not using interrupt
# click = sensor.getClick()
# if (click & 0x30) :
# print "Click detected (0x%2X)" % (click)
# if (click & 0x10): print " single click"
# if (click & 0x20): print " double click"