-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgesture_control.py
62 lines (33 loc) · 996 Bytes
/
gesture_control.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import smbus
import time
bus = smbus.SMBus(1)
bus.write_byte_data(0x53, 0x2C, 0x0A)
bus.write_byte_data(0x53, 0x2D, 0x08)
bus.write_byte_data(0x53, 0x31, 0x08)
time.sleep(0.5)
data0 = bus.read_byte_data(0x53, 0x32)
data1 = bus.read_byte_data(0x53, 0x33)
xAccl = ((data1 & 0x03) * 256) + data0
if xAccl > 511 :
xAccl -= 1024
data0 = bus.read_byte_data(0x53, 0x34)
data1 = bus.read_byte_data(0x53, 0x35)
yAccl = ((data1 & 0x03) * 256) + data0
if yAccl > 511 :
yAccl -= 1024
data0 = bus.read_byte_data(0x53, 0x36)
data1 = bus.read_byte_data(0x53, 0x37)
zAccl = ((data1 & 0x03) * 256) + data0
if zAccl > 511 :
zAccl -= 1024
print "Acceleration in X-Axis : %d" %xAccl
print "Acceleration in Y-Axis : %d" %yAccl
print "Acceleration in Z-Axis : %d" %zAccl
if (xAccl<0 and zAccl>0 and yAccl<0):
print "Up"
if (xAccl<0 and zAccl>0 and yAccl>0):
print "Right"
if (yAccl<0 and zAccl>0 and xAccl>0):
print "Up"
if (yAccl>0 and zAccl<0 and xAccl<0):
print "Down"