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

2 years ago
  1. #define SELECT 8
  2. #define IN_SC 7
  3. #define IN_AB 6
  4. #define IN_LEFT 5
  5. #define IN_RIGHT 4
  6. #define IN_UP 3
  7. #define IN_DOWN 2
  8. #define STATUS 13
  9. #define GETSTATE(pin,bitpos,buttons) digitalRead(pin) ? (buttons | (1<<bitpos) ) : (buttons & (buttons ^ (1<<bitpos)))
  10. byte buttons = 0;
  11. byte buttons_prev = 0;
  12. byte buttons_other = 240;
  13. byte buttons_other_prev = 0;
  14. bool rmode = 1;
  15. long int count = 0;
  16. void setup() {
  17. Serial.begin(9600);
  18. digitalWrite(SELECT,HIGH);
  19. pinMode(SELECT, OUTPUT);
  20. pinMode(IN_SC, INPUT);
  21. pinMode(IN_AB, INPUT);
  22. pinMode(IN_LEFT, INPUT);
  23. pinMode(IN_RIGHT, INPUT);
  24. pinMode(IN_UP, INPUT);
  25. pinMode(IN_DOWN, INPUT);
  26. pinMode(STATUS, OUTPUT);
  27. }
  28. void loop() {
  29. rmode != rmode;
  30. count++;
  31. digitalWrite(SELECT,HIGH); //Pulse 1
  32. delay(5);
  33. buttons = GETSTATE(IN_AB,2,buttons); //B
  34. buttons = GETSTATE(IN_SC,3,buttons); //C
  35. buttons = GETSTATE(IN_LEFT,4,buttons); //Left
  36. buttons = GETSTATE(IN_RIGHT,5,buttons); //Right
  37. buttons = GETSTATE(IN_DOWN,6,buttons); //Down
  38. buttons = GETSTATE(IN_UP,7,buttons); //Up
  39. digitalWrite(SELECT,LOW);
  40. buttons = GETSTATE(IN_SC,0,buttons); //Start
  41. buttons = GETSTATE(IN_AB,1,buttons); //A
  42. digitalWrite(SELECT,HIGH); //Pulse 2
  43. digitalWrite(SELECT,LOW);
  44. digitalWrite(SELECT,HIGH); //Pulse 3
  45. digitalWrite(SELECT,LOW); //Pulse 4 (XYZ)
  46. digitalWrite(SELECT,HIGH); //XYZ Mode
  47. buttons_other = GETSTATE(IN_RIGHT,0,buttons_other); //Mode
  48. buttons_other = GETSTATE(IN_LEFT,1,buttons_other); //X
  49. buttons_other = GETSTATE(IN_DOWN,2,buttons_other); //Y
  50. buttons_other = GETSTATE(IN_UP,3,buttons_other); //Z
  51. digitalWrite(SELECT,LOW); //snussy mode
  52. //output only on change
  53. if (rmode && ((buttons_prev != buttons) || (buttons_other_prev != buttons_other))) {
  54. Serial.write(buttons);
  55. Serial.write(buttons_other);
  56. //Serial.println(buttons | buttons_other<<8,BIN);
  57. //Serial.println(,BIN);
  58. }
  59. buttons_other_prev = buttons_other;
  60. buttons_prev = buttons;
  61. }