Skip to content

manasdas17/arduino-gamepad

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Simple Arduino joystick + button, Python controlled

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 89.1%
  • Other 10.4%
  • Shell 0.5%