Hi,
I am doing a project to add a control pad port to a portable game console.
The control pad uses a DE9 connector, and in order to read all of the buttons, I have to first supply 5V to the "select" pin, read the 6 data pins, then supply 0V to the "select" pin and re-read them to see values for the remaining buttons.
When the states are read, I then output via some digital pins to make some transistors switch the relevant buttons on the game console circuit. At the moment I am using LEDs instead of the transistors attached to the game console button contacts.
I have managed to make a loop that scans the pins in one state or the other, but I don't know how to switch between states and scan all the buttons and keep the outputs (LEDs) updated with their last states.
I will upload some videos to illustrate what's going on. Here is the code that works in either one state or another, thanks for reading:
/*
Genesis Control Pad Reader
This program reads pins from the Genesis controller and lights up
appropriate LEDs to show which buttons have been pressed.
*/
//Setting up the pins for the inputs, and initialising
//the states of the LED variables
const int upPin = 8;
int upState = LOW;
const int downPin = 9;
int downState = LOW;
const int leftPin = 10;
int leftState = LOW;
const int rightPin = 11;
int rightState = LOW;
const int onePin = 12;
int oneState = LOW;
const int startPin = 13;
int startState = LOW;
const int twoPin = A0;
int twoState = LOW;
int selectPin = 6;
//Setting the pins to read and write
void setup() {
pinMode(0, INPUT);
pinMode(2, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(5, INPUT);
pinMode(selectPin, OUTPUT);
pinMode(7, INPUT);
pinMode(upPin, OUTPUT);
pinMode(downPin, OUTPUT);
pinMode(leftPin, OUTPUT);
pinMode(rightPin, OUTPUT);
pinMode(onePin, OUTPUT);
pinMode(startPin, OUTPUT);
pinMode(twoPin, OUTPUT);
}
void loop() {
int up = digitalRead(0);
int down = digitalRead(2);
int left = digitalRead(A2);
int right = digitalRead(A1);
int ab = digitalRead(5);
int cs = digitalRead(7);
digitalWrite(selectPin, LOW); //This is the select pin that switches between states. I need to do this automatically
if (up == HIGH)
upState = LOW;
else
upState = HIGH;
if (down == HIGH)
downState = LOW;
else
downState = HIGH;
if (left == HIGH)
leftState = LOW;
else
leftState = HIGH;
if (right == HIGH)
rightState = LOW;
else
rightState = HIGH;
if (ab == HIGH)
oneState = LOW;
else
oneState = HIGH;
if (cs == HIGH)
twoState = LOW;
else
twoState = HIGH;
digitalWrite(upPin, upState);
digitalWrite(downPin, downState);
digitalWrite(leftPin, leftState);
digitalWrite(rightPin, rightState);
digitalWrite(onePin, oneState);
digitalWrite(twoPin, twoState);
}
I found the control pad protocol here:
http://www.msarnoff.org/gen2usb/
Edit: Here is the video showing what happens: