Guest User

Untitled

a guest
Feb 18th, 2017
123
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Bounce.h>
  2.  
  3. #define NUM_BUTTONS 16 //(inc directional buttons)
  4.  
  5. #define A_PIN 15
  6. #define B_PIN 16
  7. #define X_PIN 14
  8. #define Y_PIN 17
  9.  
  10. #define RJOY_SEL_PIN 18
  11. #define RJOY_X_PIN 6 //analog
  12. #define RJOY_Y_PIN 7 //analog
  13.  
  14. #define LJOY_SEL_PIN 7
  15. #define LJOY_X_PIN 8 //analog
  16. #define LJOY_Y_PIN 9 //analog
  17.  
  18. #define R_PIN 8
  19. #define D_PIN 9
  20. #define L_PIN 10
  21. #define U_PIN 11
  22.  
  23. #define LSHOL_PIN 0
  24. #define LTRIG_PIN 1
  25.  
  26. #define RSHOL_PIN 2
  27. #define RTRIG_PIN 3
  28.  
  29. #define SELECT_PIN 5
  30. #define START_PIN 6
  31.  
  32. Bounce btn_x = Bounce(X_PIN, 10);
  33. Bounce btn_a = Bounce(A_PIN, 10);
  34. Bounce btn_b = Bounce(B_PIN, 10);
  35. Bounce btn_y = Bounce(Y_PIN, 10);
  36. Bounce btn_Rjoysel = Bounce(RJOY_SEL_PIN, 10);
  37.  
  38. Bounce btn_up = Bounce(U_PIN, 10);
  39. Bounce btn_right = Bounce(R_PIN, 10);
  40. Bounce btn_down = Bounce(D_PIN, 10);
  41. Bounce btn_left = Bounce(L_PIN, 10);
  42. Bounce btn_Ljoysel = Bounce(LJOY_SEL_PIN, 10);
  43.  
  44. Bounce btn_RShoulder = Bounce(RSHOL_PIN, 10);
  45. Bounce btn_RTrigger = Bounce(RTRIG_PIN, 10);
  46. Bounce btn_LShoulder = Bounce(LSHOL_PIN, 10);
  47. Bounce btn_LTrigger = Bounce(LTRIG_PIN, 10);
  48.  
  49. Bounce btn_start = Bounce(START_PIN, 10);
  50. Bounce btn_select = Bounce(SELECT_PIN, 10);
  51.  
  52. Bounce buttons[NUM_BUTTONS] =
  53. {
  54. btn_a, //RIGHT SIDE
  55. btn_b,
  56. btn_x,
  57. btn_y,
  58. btn_Rjoysel,
  59.  
  60. btn_up, //LEFT SIDE
  61. btn_right, //MAYBE SET AS HAT? need to convert to angle
  62. btn_down,
  63. btn_left,
  64. btn_Ljoysel,
  65.  
  66. btn_RShoulder, //SHOULDER BUTTONS
  67. btn_RTrigger,
  68. btn_LShoulder,
  69. btn_LTrigger,
  70.  
  71. btn_start, //START SELECT
  72. btn_select
  73. };
  74.  
  75. Bounce dpad_buttons[4]{
  76. btn_up,
  77. btn_down,
  78. btn_left,
  79. btn_right
  80. };
  81.  
  82. void setup() {
  83. // put your setup code here, to run once:
  84. //retropie controller setup
  85. pinMode(13, OUTPUT);
  86. digitalWrite(13, HIGH);
  87.  
  88. pinMode(A_PIN, INPUT_PULLUP);
  89. pinMode(B_PIN, INPUT_PULLUP);
  90. pinMode(X_PIN, INPUT_PULLUP);
  91. pinMode(Y_PIN, INPUT_PULLUP);
  92. pinMode(RJOY_SEL_PIN, INPUT_PULLUP);
  93.  
  94. pinMode(U_PIN, INPUT_PULLUP);
  95. pinMode(D_PIN, INPUT_PULLUP);
  96. pinMode(R_PIN, INPUT_PULLUP);
  97. pinMode(L_PIN, INPUT_PULLUP);
  98. pinMode(LJOY_SEL_PIN, INPUT_PULLUP);
  99.  
  100. pinMode(RTRIG_PIN, INPUT_PULLUP);
  101. pinMode(RSHOL_PIN, INPUT_PULLUP);
  102. pinMode(LTRIG_PIN, INPUT_PULLUP);
  103. pinMode(LSHOL_PIN, INPUT_PULLUP);
  104.  
  105. pinMode(START_PIN, INPUT_PULLUP);
  106. pinMode(SELECT_PIN, INPUT_PULLUP);
  107. }
  108.  
  109. void loop() {
  110. // put your main code here, to run repeatedly:
  111. Joystick.X(map(analogRead(LJOY_X_PIN), 0, 1023, 1023, 0));
  112. Joystick.Y(analogRead(LJOY_Y_PIN));
  113.  
  114. Joystick.Z(analogRead(RJOY_Y_PIN));
  115. Joystick.Zrotate(analogRead(RJOY_X_PIN));
  116.  
  117. for(int i = 0; i < NUM_BUTTONS; i++){
  118. buttons[i].update();
  119.  
  120. if(buttons[i].fallingEdge()){
  121. Joystick.button(i+1, 1);
  122. }
  123. if(buttons[i].risingEdge()){
  124. Joystick.button(i+1, 0);
  125. }
  126. }
  127. uint8_t readDPad =0;
  128. // for(int i = 0; i < 4; i++){
  129. // dpad_buttons[i].update();
  130. // readDPad |= !(dpad_buttons[i].read()) << i;
  131. // }
  132. // switch(readDPad){
  133. // //up 1
  134. // //down 2
  135. // //left 4
  136. // //right 8
  137. // case 1:
  138. // Joystick.hat(0); //N
  139. // break;
  140. // case 2:
  141. // Joystick.hat(180);//S
  142. // break;
  143. // case 4:
  144. // Joystick.hat(270);//W
  145. // break;
  146. // case 8:
  147. // Joystick.hat(90); //E
  148. // break;
  149. // case 5:
  150. // Joystick.hat(315);//NW
  151. // break;
  152. // case 9:
  153. // Joystick.hat(45); //NE
  154. // break;
  155. // case 6:
  156. // Joystick.hat(225);//SW
  157. // break;
  158. // case 10:
  159. // Joystick.hat(135);//SE
  160. // break;
  161. // default:
  162. // Joystick.hat(-1); //CENTRE
  163. // break;
  164. // }
  165.  
  166. }
RAW Paste Data