Created
April 12, 2018 23:14
-
-
Save omiq/83a70a467ffcbba322ba3d76f98e6145 to your computer and use it in GitHub Desktop.
Simple example of controlling a Pi using a game pad using python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from evdev import InputDevice | |
# create object to read input - specify YOUR device | |
controller = InputDevice('/dev/input/event0') | |
# want to display ALL info? | |
debug = False | |
# what are the controller details? | |
print(controller) | |
# read controller info in an infinite loop | |
for event in controller.read_loop(): | |
# here I am looking for the start button | |
# so I can quit | |
if event.type == 1: | |
exit() | |
# set as true above if you want to look up | |
# different button values | |
if debug: | |
print("\n\nEvent Type:{}".format(event.type)) | |
print("Event Code:{}".format(event.code)) | |
print("Event Value:{}".format(event.value)) | |
# look for pad moves | |
if event.type == 3: | |
# up and down is 17 | |
if event.code == 17: | |
if event.value == -1: | |
print("\n\n\nPad Up\n") | |
if event.value == 1: | |
print("\n\n\nPad Down\n") | |
# left and right is 16 | |
if event.code == 16: | |
if event.value == -1: | |
print("\n\n\nPad Left\n") | |
if event.value == 1: | |
print("\n\n\nPad Right\n") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment