-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
80 lines (57 loc) · 1.25 KB
/
run.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/python
#Setup
import Adafruit_BBIO.PWM as pwm
import sys, os
import XboxController
import time
pin1 = "P9_14"
pin2 = "P8_19"
frequency = 50
# 5% = 1ms @ 50hz
# 10% = 2ms @ 50hz
duty = 7.50
# pwm.start
pwm.start(pin1, duty, frequency)
pwm.start(pin2, duty, frequency)
'''
while True:
duty = input("enter duty:")
print "You said:",duty
if duty == 99:
duty = 7.5
pwm.set_duty_cycle(pin, duty)
print "Running at ", duty, "%"
if duty == 0:
pwm.stop(pin)
pwm.cleanup()
sys.exit()
'''
def myCallback(controlId, value):
duty = value / 10 + 7.5
print value, duty
def leftTrigger(value):
duty = value / 10 + 7.5
pwm.set_duty_cycle(pin1, duty)
def rightTrigger(value):
duty = value / 10 + 7.5
pwm.set_duty_cycle(pin2, duty)
xboxCont = XboxController.XboxController(
controllerCallBack = myCallback,
joystickNo = 0,
deadzone = 15,
scale = 25,
invertYAxis = False)
xboxCont.setupControlCallback(xboxCont.XboxControls.LTRIGGER, leftTrigger)
xboxCont.setupControlCallback(xboxCont.XboxControls.RTRIGGER, rightTrigger)
try:
xboxCont.start()
print "Controller Ready"
while True:
time.sleep(0.1)
except KeyboardInterrupt:
print "User Quit"
finally:
xboxCont.stop()
pwm.stop(pin1)
pwm.stop(pin2)
pwm.cleanup()