Hello guys, I'm Sarvesh. A couple of days ago I wanted to play some retro games. So I installed them on my Pc. But I could only play with my Pc's keyboard and that did not give the feel of my childhood days. So I decided to build a gamepad for my Pc that can play old as well as new games(Not all). I used a old gaming controller and modified it to create this awesome Gamepad. This is a wired game pad for PC. It can be used to play emulator and PC games. Also the joystick can serve as a mouse for your PC. The Game pad is controlled using an Arduino Pro Micro.
Step 1 : Circuit Diagram & Key MappingConnect all the components according to the circuit diagram (1st image) given above.
I would recommend to first check all the connections and working on a breadboard.
Key mapping :
The layout of my actual button placement is also shown above (2nd image) to give you a clear idea which button is positioned where, what label it is programmed with and what character it sends to the computer.
Step 2 : Code for the ArduinoNow download the code and install the mouse.h and keyboard.h libraries. Upload the code to your Arduino.
You can copy the code from below.
#include<Mouse.h>
#include <Keyboard.h>
const int EMG = 2; //Emergency stop button :)
const int L1 = 7;
const int L2 = 8;
const int P1 = 9;
const int R1 = 14;
const int R2 = 16;
const int P2 = 10;
const int D1 = 4;
const int D2 = 5;
const int D3 = 6;
const int D4 = 3;
const int SWITCH = 15; // digital pin 2 connected to SW output of JoyStick
const int X_AX = A1; // analog pin 0 connected to X output of JoyStick
const int Y_AX = A0; // analog pin 1 connected to Y output of JoyStick
int range = 10; // output range or speed of X or Y movement
int responseDelay = 5; // response delay of the mouse, in ms
int threshold = range / 4; // resting threshold
int center = range / 2;
int EMGState = HIGH;
int L1S = LOW;
int L2S = LOW;
int P1S = LOW;
int R1S = LOW;
int R2S = LOW;
int P2S = LOW;
int D1S = LOW;
int D2S = LOW; //PREVIOUS STATES
int D3S = LOW;
int D4S = LOW;
void setup()
{
pinMode(EMG, INPUT);
pinMode(L1, INPUT);
pinMode(L2, INPUT);
pinMode(P1, INPUT);
pinMode(D1, INPUT);
pinMode(D2, INPUT);
pinMode(D3, INPUT);
pinMode(D4, INPUT);
pinMode(R1, INPUT);
pinMode(R2, INPUT);
pinMode(P2, INPUT);
pinMode(SWITCH, INPUT_PULLUP);
Serial.begin(9600);
Keyboard.begin();
Mouse.begin();
}
void loop()
{
EMGState = digitalRead(EMG);
if (EMGState == HIGH)
{
Serial.println("FAULT");
Keyboard.releaseAll();
Keyboard.end();
Mouse.end();
}
else
{
//Serial.println("OK");
int L1STATE = digitalRead(L1);
int L2STATE = digitalRead(L2);
int P1STATE = digitalRead(P1);
int D1STATE = digitalRead(D1);
int D2STATE = digitalRead(D2);
int D3STATE = digitalRead(D3);
int D4STATE = digitalRead(D4);
int R1STATE = digitalRead(R1);
int R2STATE = digitalRead(R2);
int P2STATE = digitalRead(P2);
if(L1STATE==HIGH && L1S == LOW)
{
Serial.println("L1 PRESSED");
Keyboard.press('K'); //K
}
if(L1STATE==LOW && L1S == HIGH)
{
Serial.println("L1 RELEASED");
Keyboard.release('K'); //K
}
if(L2STATE==HIGH && L2S == LOW)
{
Serial.println("L2 PRESSED");
Keyboard.press('J'); //J
}
if(L2STATE==LOW && L2S == HIGH)
{
Serial.println("L2 RELEASED");
Keyboard.release('J'); //J
}
if(P1STATE==HIGH && P1S == LOW)
{
Serial.println("P1 PRESSED");
Keyboard.press('H'); //H
}
if(P1STATE==LOW && P1S == HIGH)
{
Serial.println("P1 RELEASED");
Keyboard.release('H'); //H
}
if(R1STATE==HIGH && R1S == LOW)
{
Serial.println("R1 PRESSED"); //L
Keyboard.press('L');
}
if(R1STATE==LOW && R1S == HIGH)
{
Serial.println("R1 RELEASED"); //L
Keyboard.release('L');
}
if(R2STATE==HIGH && R2S == LOW)
{
Serial.println("R2 PRESSED"); //G
Keyboard.press('G');
}
if(R2STATE==LOW && R2S == HIGH)
{
Serial.println("R2 RELEASED"); //G
Keyboard.release('G');
}
if(P2STATE==HIGH && P2S == LOW)
{
Serial.println("P2 PRESSED"); //F
Keyboard.press('F');
}
if(P2STATE==LOW && P2S == HIGH)
{
Serial.println("P2 RELEASED"); //F
Keyboard.release('F');
}
if(D1STATE==HIGH && D1S == LOW)
{
Serial.println("D1 PRESSED"); //W
Keyboard.press('W');
}
if(D1STATE==LOW && D1S == HIGH)
{
Serial.println("D1 RELEASED"); //W
Keyboard.release('W');
}
if(D2STATE==HIGH && D2S==LOW)
{
Serial.println("D2 PRESSED"); //A
Keyboard.press('A');
}
if(D2STATE==LOW && D2S==HIGH)
{
Serial.println("D2 RELEASED"); //A
Keyboard.release('A');
}
if(D3STATE==HIGH && D3S==LOW)
{
Serial.println("D3 PRESSED"); //S
Keyboard.press('S');
}
if(D3STATE==LOW && D3S==HIGH)
{
Serial.println("D3 RELEASED"); //S
Keyboard.release('S');
}
if(D4STATE==HIGH && D4S==LOW)
{
Serial.println("D4 PRESSED"); //D
Keyboard.press('D');
}
if(D4STATE==LOW && D4S==HIGH)
{
Serial.println("D4 RELEASED"); //D
Keyboard.release('D');
}
L1S = L1STATE;
L2S = L2STATE;
P1S = P1STATE;
R1S = R1STATE;
R2S = R2STATE;
P2S = P2STATE;
D1S = D1STATE;
D2S = D2STATE;
D3S = D3STATE;
D4S = D4STATE;
int xReading = readAxis(A1);
int yReading = readAxis(A0);
Mouse.move(xReading, yReading, 0);
if (digitalRead(SWITCH) == LOW)
{
if (!Mouse.isPressed(MOUSE_LEFT))
{
Mouse.press(MOUSE_LEFT);
}
}
else
{
if (Mouse.isPressed(MOUSE_LEFT))
{
Mouse.release(MOUSE_LEFT);
}
}
delay(responseDelay);
}
}
int readAxis(int thisAxis)
{
int reading = analogRead(thisAxis);
reading = map(reading, 0, 1023, 0, range);
int distance = reading - center;
if (abs(distance) < threshold)
{
distance = 0;
}
return distance;
}
Step 3 : Cutting, Painting and SolderingFirst cut the PCB according to the size of the Game pad and align the push buttons and the joystick module.
Then paint the game pad with the color of your choice.
Now solder the push buttons and joystick on general purpose pcb.
Then fix the limit switches in their positions with the help of some super glue.
Solder the remaining components and do a final test.
I have attached images below for reference.
And here is how the final project looks like.
Comments