forked from ali-raheem/eZ430-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pass-the-ball.py
executable file
·65 lines (53 loc) · 1.04 KB
/
pass-the-ball.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
63
64
65
#!/usr/bin/env python
import eZ430
import time
import urllib2
#Wireless link init
watch = eZ430.watch("/dev/tty.usbmodem001")
#Variables
current = 1
baseurl = "http://localhost:8080/"
def neutral():
print "Neutral"
def left():
print "Left"
try:
urllib2.urlopen(baseurl + "moveleft")
except urllib2.URLError:
error()
def right():
print "Right"
try:
urllib2.urlopen(baseurl + "moveright")
except urllib2.URLError:
error()
def error():
print "Some error in opening url"
#Gestures
while 1:
time.sleep(1)
data = watch.read()
acc={'x':ord(data[0]), 'y':ord(data[1]), 'z':ord(data[2])}
if acc['x']+acc['y']+acc['z']!=0:
# print "x: %s\ty:%s\tz:%s\tpd:%s"%(acc['x'],acc['y'],acc['z'],pd)
x=acc['x']
y=acc['y']
z=acc['z']
#left
if (y > 220 and y < 235):
print "l"
if (current != 0):
current = 0
left()
#neutral
if (y > 210 and y < 215):
print "n"
if (current != 1):
current = 1
neutral()
#right
if (y > 0 and y < 20):
print "r"
if (current != 2):
current = 2
right()