This is a Teensy-based USB converter for using a SEGA Master System control pad with an emulator. See in the Setup() function below for the hardware configuration. I used a male 9 pin cable for the converter so that I didn't have to splice an actual SEGA control pad cable.
The converter takes button presses from the control pad and sends them to the computer as keyboard presses and releases. W is up, S is down, A is left, D is right, J is button 1 and K is button 2. Simply setup the emulator of your choice with these keyboard buttons.
byte button_1;
byte button_1_previous;
byte button_2;
byte button_2_previous;
byte button_3;
byte button_3_previous;
byte button_4;
byte button_4_previous;
byte button_5;
byte button_5_previous;
byte button_6;
byte button_6_previous;
void setup() {
pinMode(0, INPUT); // up direction = SEGA joystick pin 1
pinMode(1, INPUT); // down direction = SEGA joystick pin 2
pinMode(2, INPUT); // left direction = SEGA joystick pin 3
pinMode(3, INPUT); // right direction = SEGA joystick pin 4
pinMode(4, INPUT); // button 1 = SEGA joystick pin 6
pinMode(5, INPUT); // button 2 = SEGA joystick pin 9
// also connect Teensy ground to joystick pin 8
digitalWrite(0, HIGH); // turn the pullup resistor on
digitalWrite(1, HIGH); // turn the pullup resistor on
digitalWrite(2, HIGH); // turn the pullup resistor on
digitalWrite(3, HIGH); // turn the pullup resistor on
digitalWrite(4, HIGH); // turn the pullup resistor on
digitalWrite(5, HIGH); // turn the pullup resistor on
}
void loop() {
button_1 = digitalRead(0);
if(button_1 != button_1_previous) {
button_1_previous = button_1;
if(button_1 == 0) {
Keyboard.set_key1(KEY_W);
}
else {
Keyboard.set_key1(0);
}
}
button_2 = digitalRead(1);
if(button_2 != button_2_previous) {
button_2_previous = button_2;
if(button_2 == 0) {
Keyboard.set_key2(KEY_S);
}
else {
Keyboard.set_key2(0);
}
}
button_3 = digitalRead(2);
if(button_3 != button_3_previous) {
button_3_previous = button_3;
if(button_3 == 0) {
Keyboard.set_key3(KEY_A);
}
else {
Keyboard.set_key3(0);
}
}
button_4 = digitalRead(3);
if(button_4 != button_4_previous) {
button_4_previous = button_4;
if(button_4 == 0) {
Keyboard.set_key4(KEY_D);
}
else {
Keyboard.set_key4(0);
}
}
button_5 = digitalRead(4);
if(button_5 != button_5_previous) {
button_5_previous = button_5;
if(button_5 == 0) {
Keyboard.set_key5(KEY_J);
}
else {
Keyboard.set_key5(0);
}
}
button_6 = digitalRead(5);
if(button_6 != button_6_previous) {
button_6_previous = button_6;
if(button_6 == 0) {
Keyboard.set_key6(KEY_K);
}
else {
Keyboard.set_key6(0);
}
}
Keyboard.send_now();
}
0 comments:
Post a Comment