A project to connect a genesis controller to USB via an Arduino board.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

61 lines
1.9 KiB

#define SELECT 8
#define IN_SC 7
#define IN_AB 6
#define IN_LEFT 5
#define IN_RIGHT 4
#define IN_UP 3
#define IN_DOWN 2
#define STATUS 13
#define GETSTATE(pin,bitpos,buttons) digitalRead(pin) ? (buttons | (1<<bitpos) ) : (buttons & (buttons ^ (1<<bitpos)))
byte buttons = 0;
byte buttons_prev = 0;
byte buttons_other = 240;
byte buttons_other_prev = 0;
bool rmode = 1;
long int count = 0;
void setup() {
Serial.begin(9600);
digitalWrite(SELECT,HIGH);
pinMode(SELECT, OUTPUT);
pinMode(IN_SC, INPUT);
pinMode(IN_AB, INPUT);
pinMode(IN_LEFT, INPUT);
pinMode(IN_RIGHT, INPUT);
pinMode(IN_UP, INPUT);
pinMode(IN_DOWN, INPUT);
pinMode(STATUS, OUTPUT);
}
void loop() {
rmode != rmode;
count++;
digitalWrite(SELECT,HIGH); //Pulse 1
delay(5);
buttons = GETSTATE(IN_AB,2,buttons); //B
buttons = GETSTATE(IN_SC,3,buttons); //C
buttons = GETSTATE(IN_LEFT,4,buttons); //Left
buttons = GETSTATE(IN_RIGHT,5,buttons); //Right
buttons = GETSTATE(IN_DOWN,6,buttons); //Down
buttons = GETSTATE(IN_UP,7,buttons); //Up
digitalWrite(SELECT,LOW);
buttons = GETSTATE(IN_SC,0,buttons); //Start
buttons = GETSTATE(IN_AB,1,buttons); //A
digitalWrite(SELECT,HIGH); //Pulse 2
digitalWrite(SELECT,LOW);
digitalWrite(SELECT,HIGH); //Pulse 3
digitalWrite(SELECT,LOW); //Pulse 4 (XYZ)
digitalWrite(SELECT,HIGH); //XYZ Mode
buttons_other = GETSTATE(IN_RIGHT,0,buttons_other); //Mode
buttons_other = GETSTATE(IN_LEFT,1,buttons_other); //X
buttons_other = GETSTATE(IN_DOWN,2,buttons_other); //Y
buttons_other = GETSTATE(IN_UP,3,buttons_other); //Z
digitalWrite(SELECT,LOW); //snussy mode
//output only on change
if (rmode && ((buttons_prev != buttons) || (buttons_other_prev != buttons_other))) {
Serial.write(buttons);
Serial.write(buttons_other);
//Serial.println(buttons | buttons_other<<8,BIN);
//Serial.println(,BIN);
}
buttons_other_prev = buttons_other;
buttons_prev = buttons;
}