Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Arnov Sharma
Published © MIT

Arduino Game Controller for NES and GBA

Made a Simple Game Controller with Seeed's XIAO M0 DEV Board and 3D Printed body.

BeginnerFull instructions provided1 hour719

Things used in this project

Hardware components

Seeed Studio XIAO SAMD21 (Pre-Soldered) - Seeeduino XIAO
Seeed Studio XIAO SAMD21 (Pre-Soldered) - Seeeduino XIAO
×1
PTS 645 Series Switch
C&K Switches PTS 645 Series Switch
×10

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

Main Body

LID

Schematics

sch

Code

code

C/C++
#include <Gamepad.h>

Gamepad gp;

void setup() {
  
  pinMode(0,  INPUT_PULLUP); //LEFTBUTTON
  pinMode(1,  INPUT_PULLUP); //RIGHTBUTTON
  pinMode(2,  INPUT_PULLUP); //UP
  pinMode(3,  INPUT_PULLUP); //DOWN
  pinMode(4,  INPUT_PULLUP); //LEFT
  pinMode(5,  INPUT_PULLUP); //RIGHT
  pinMode(6,  INPUT_PULLUP); //A
  pinMode(7,  INPUT_PULLUP); //B  
  pinMode(8,  INPUT_PULLUP); //START
  pinMode(9,  INPUT_PULLUP); //STOP 
  
}

void loop() {
  
  int UPLEFT, UPRIGHT, UP, DOWN, LEFT, RIGHT, RIGHTBUTTON, LEFTBUTTON, A, B, START, STOP;

  RIGHTBUTTON = digitalRead(0);
  LEFTBUTTON = digitalRead(1);
  UP = digitalRead(2);
  DOWN = digitalRead(3);
  LEFT = digitalRead(4);
  RIGHT = digitalRead(5);
  A = digitalRead(6);
  B = digitalRead(7);
  START = digitalRead(8);
  STOP = digitalRead(9);
  
      
  if(UP == LOW)
    gp.setButtonState(2, true);
  else
    gp.setButtonState(2, false);

  if(DOWN == LOW)
    gp.setButtonState(3, true);
  else
    gp.setButtonState(3, false);    

  if(LEFT == LOW)
    gp.setButtonState(4, true);
  else
    gp.setButtonState(4, false); 

  if(RIGHT == LOW)
    gp.setButtonState(5, true);
  else
    gp.setButtonState(5, false);     

  if(RIGHTBUTTON == LOW)
    gp.setButtonState(1, true);
  else
    gp.setButtonState(1, false);   

  if(LEFTBUTTON == LOW)
    gp.setButtonState(0, true);
  else
    gp.setButtonState(0, false);     

  if(A == LOW)
    gp.setButtonState(6, true);
  else
    gp.setButtonState(6, false);  

  if(B == LOW)
    gp.setButtonState(7, true);
  else
    gp.setButtonState(7, false);  

  if(START == LOW)
    gp.setButtonState(8, true);
  else
    gp.setButtonState(8, false);   

  if(STOP == LOW)
    gp.setButtonState(9, true);
  else
    gp.setButtonState(9, false); 

  delay(20);
}

Credits

Arnov Sharma

Arnov Sharma

310 projects • 311 followers
Just your average MAKER

Comments