forked from KeplerElectronics/Basic_Analog_Drive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasic_Analog_Drive.py
33 lines (30 loc) · 1.18 KB
/
Basic_Analog_Drive.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
#Created by Kepler Electronics, https://www.youtube.com/keplerelectronics
import explorerhat
import time
explorerhat.motor.one.invert()
from evdev import InputDevice, ecodes
while 1==1:
try:
fh = open('/dev/input/event0')
print('controller found')
gamepad = InputDevice('/dev/input/event0')
print(gamepad)
for event in gamepad.read_loop():
if event.type == ecodes.EV_ABS:
if event.code == 5:
if event.value > 155:
explorerhat.motor.one.forwards(event.value-155)
elif event.value < 100:
explorerhat.motor.one.backwards((100-event.value))
else:
explorerhat.motor.one.stop()
elif event.code == 1:
if event.value > 155:
explorerhat.motor.two.forwards(event.value-155)
elif event.value < 100:
explorerhat.motor.two.backwards((100-event.value))
else:
explorerhat.motor.two.stop()
except IOError:
time.sleep(1)
print('Controller Not Found')