-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample.py
More file actions
61 lines (57 loc) · 1.23 KB
/
sample.py
File metadata and controls
61 lines (57 loc) · 1.23 KB
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
import xbox
# Format floating point number to string format -x.xxx
def fmtFloat(n):
return '{:6.3f}'.format(n)
joy = xbox.Joystick()
print "Xbox controller sample: Press Back button to exit"
# Loop until back button is pressed
while not joy.Back():
# Show connection status
if joy.connected():
print "Connected ",
else:
print "Disconnected",
# Left analog stick
print "Lx,Ly ",fmtFloat(joy.leftX()),fmtFloat(joy.leftY()),
# Right trigger
print "Rtrg ",fmtFloat(joy.rightTrigger()),
# A/B/X/Y buttons
print "Buttons ",
if joy.A():
print "A",
else:
print " ",
if joy.B():
print "B",
else:
print " ",
if joy.X():
print "X",
else:
print " ",
if joy.Y():
print "Y",
else:
print " ",
# Dpad U/D/L/R
print "Dpad ",
if joy.dpadUp():
print "U",
else:
print " ",
if joy.dpadDown():
print "D",
else:
print " ",
if joy.dpadLeft():
print "L",
else:
print " ",
if joy.dpadRight():
print "R",
else:
print " ",
# Move cursor back to start of line
print chr(13),
# Close out when done
joy.close()