VinVout-io
Published © GPL3+

Arduino UNO Game Controller

A DIY game controller using Arduino Uno

BeginnerFull instructions provided1 hour4,524
Arduino UNO Game Controller

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Tactile Switch, Top Actuated
Tactile Switch, Top Actuated
×4
Resistor 220 ohm
Resistor 220 ohm
×4

Story

Read more

Schematics

Schematic

just wire it up

Code

Python code for the controller

Python
remember to install pyfirmata and keyboard
''' Game controller
python for serial communication
what to do
when pressing a pushbutton send w/a/s/d to the computer'''

"""https://github.com/boppreh/keyboard"""
import pyfirmata
import keyboard
import time

board = pyfirmata.Arduino('/dev/ttyUSB0')   #Find the port from arduino ide

it = pyfirmata.util.Iterator(board)
it.start()

w_pin=board.get_pin('d:6:i')
a_pin=board.get_pin('d:11:i')
s_pin=board.get_pin('d:13:i')
d_pin=board.get_pin('d:8:i')


while True:
    w=w_pin.read()        
    if w==1:           
        keyboard.press("w")
    elif w==0:
        keyboard.release("w")
           
    a=a_pin.read()
    if a==1:
        keyboard.press("a")
    elif a==0:
        keyboard.release("a")
       
    s=s_pin.read()
    if s==1:
        keyboard.press("s")
    elif s==0:
        keyboard.release("s")
       
    d=d_pin.read()
    if d is True:
        keyboard.press("d")
    elif d is False:
        keyboard.release("d")

Credits

VinVout-io

VinVout-io

10 projects • 5 followers
Electronics enthusiast. part-time Youtuber

Comments