-
Notifications
You must be signed in to change notification settings - Fork 1
/
redgear1.py
83 lines (77 loc) · 1.69 KB
/
redgear1.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
80
81
82
83
from evdev import InputDevice,categorize,ecodes
import RPi.GPIO as GPIO
gamepad = InputDevice('/dev/input/event0')
#button codes
CA=304 #0,1
CB=305 #0,1
CY=308 #0,1
CX=307 #0,1
CR1=311 #0,1
CL1=310 #0,1
Cback=314 #0,1
Cstart=315 #0,1
Chome=316 #0,1
CL3=317 #0,1
CR3=318 #0,1
CR2=5 #0,255
CL2=2 #0,255
CLX=0 #-32768,32767
CLY=1 #-32768,32767 sign inverted
CRX=3 #-32768,32767
CRY=4 #-32768,32767 sign inverted
CH=16 #-1,0,1
CV=17 #-1,0,1 sign inverted
#GPIOPins
MRf=2
MRb=3
MRe=4
MLf=5
MLb=6
MLe=7
GPIO.setwarnings(False)
GPIO.cleanup()
GPIO.setmode(GPIO.BCM)
GPIO.setup(MRf,GPIO.OUT)
GPIO.setup(MRb,GPIO.OUT)
GPIO.setup(MRe,GPIO.OUT)
GPIO.setup(MLf,GPIO.OUT)
GPIO.setup(MLb,GPIO.OUT)
GPIO.setup(MLe,GPIO.OUT)
Trx=0
Try=0
MRs=0
MLs=0
for event in gamepad.read_loop():
if event.code is CRY:
Try=-event.value/415
if event.code is CRX:
Trx=(event.value/365)/4
MRs=Try-Trx
MLs=Try+Trx
MRo=GPIO.PWM(MRe,50)
MLo=GPIO.PWM(MLe,50)
if(MRs>=0):
if(MRs>100):
MRs=100
GPIO.output(MRf,GPIO.HIGH)
GPIO.output(MRb,GPIO.LOW)
MRo.start(MRs)
if(MRs<0):
if(MRs<-100):
MRs=-100
GPIO.output(MRf,GPIO.LOW)
GPIO.output(MRb,GPIO.HIGH)
MRo.start(-MRs)
if(MLs>=0):
if(MLs>100):
MLs=100
GPIO.output(MLf,GPIO.HIGH)
GPIO.output(MLb,GPIO.LOW)
MLo.start(MLs)
if(MLs<0):
if(MLs<-100):
MLs=-100
GPIO.output(MLf,GPIO.LOW)
GPIO.output(MLb,GPIO.HIGH)
MLo.start(-MLs)
print "LS= "+str(MLs)+" RS= "+str(MRs)