Simple Arduino joystick + button, Python controlled
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
gamepad
src
.gitignore
README.md
gamepad.fzz
gamepad.jpg
gamepad.png
ino.ini
ino.sh
snake.py

README.md

Arduino Gamepad

Load Arduino Sketch

Then build and upload the Arduino sketch. I use inotool for that

ino build && ino upload

Use example

from serial import Serial
from gamepad import Gamepad

serial = Serial('/dev/ttyUSB0')
gamepad = Gamepad(serial)

Create the callback function

def move(self, event):
    print 'move', event.state.get_axes()

Attach the callback to an event

gamepad.on('move', move)
gamepad.listen()

Events

move
move-x
move-y
move-right
move-left
move-up
move-down
move-center
button
button-press
button-release
switch
switch-press
switch-release

Special events

The move-right, move-left, move-up and move-down events are holding when were fired and unholding when the move-center event is fired.

This is useful if you want to run some code by a timer. For example, imagine you want to implement pacman like game. If you move left the pacman will continue move left until it hit the next wall.

def move(event):
    while gamepad.is_holding(event):
        print 'move',
        if event.is_move_left():
            print 'left'
        elif event.is_move_right():
            print 'right'
        elif event.is_move_up():
            print 'up'
        elif event.is_move_down():
            print 'down'
        time.sleep(1)

def move_center(event):
    print "center", event.state.get_axes()

gamepad.on('move', move)
gamepad.on('move-center', move_center)
gamepad.listen()

Full example using a rgb led matrix: Snake

This is an example using another project: arduino-matrix-rgb

Snake Arduino