Advertisement
Guest User

Untitled

a guest
Jan 12th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.52 KB | None | 0 0
  1. #include <Gamecube.h>
  2. #include <GamecubeAPI.h>
  3. #include <Gamecube_N64.h>
  4. #include <N64.h>
  5. #include <N64API.h>
  6. #include <Nintendo.h>
  7.  
  8. #include "Nintendo.h"
  9. /* This code uses the Nicohood Library
  10. * Use this code at your own risk
  11. * Code written by Simple Controllers and this code is open source.
  12. * Meaning its free to share, improve on, or anything you like!
  13. * Just remember to mention you used my code!
  14. * Version 2.0 I just suck at github
  15. */
  16. //This makes the controller bidirection data line on pin number8
  17. CGamecubeConsole GamecubeConsole(8); //Defines a "Gamecube Console" sending data to the console on pin 8
  18. Gamecube_Data_t d = defaultGamecubeData; //Structure for data to be sent to console
  19.  
  20. //This is needed but you don't need a controller on pin 7
  21. CGamecubeController GamecubeController1(7);
  22.  
  23. //This is the pinout of the controller. Can be changed to your liking. I may have mixed up some of the tilt pins but you can change that physically in your build or through the code. Just do test runs along the way.
  24. const int A = 22;
  25. const int B = 24;
  26. const int X = 26;
  27. const int Y = 28;
  28. const int Z = 30;
  29. const int START = 31;
  30.  
  31. const int R = 34;
  32. const int L = 35;
  33. const int RLIGHT = 36;
  34. //This is the value of analog shielding 74 is lightest possible on gamecube. It varies from gamecube to dolphin no idea why.
  35. const int RLIGHTv = 74;
  36.  
  37. const int LEFT = 38;
  38. const int RIGHT = 39;
  39. const int UP = 40;
  40. const int DOWN = 41;
  41.  
  42. //NEW!! Fixed the mixup of X1 and X2 buttons, they now correspond to the correct buttons.
  43. //If you are updating from 1.0/1.1 you might have to change the internal pins on your box or just swap the pin numbers here.
  44. const int X1 = 44;
  45. const int X2 = 45;
  46. const int Y1 = 46;
  47. const int Y2 = 47;
  48.  
  49. //This is analog tilt modifiers and can be changed to your liking
  50. const int X1v = 27;
  51. const int X2v = 55;
  52. const int X3v = 73;
  53.  
  54. const int Y1v = 27;
  55. const int Y2v = 53;
  56. const int Y3v = 74;
  57.  
  58. const int CLEFT = 48;
  59. const int CRIGHT = 49;
  60. const int CUP = 50;
  61. const int CDOWN = 51;
  62.  
  63. //THIS IS THE SWITCH/BUTTON TO TOGGLE MODIFIERS (X1, X2, Y1, Y2) TO DPAD
  64. const int SWITCH = 12;
  65.  
  66. void setup()
  67. {
  68. //This is establishing the pin assignments up there to input pins
  69. pinMode(A, INPUT_PULLUP);
  70. pinMode(B, INPUT_PULLUP);
  71. pinMode(X, INPUT_PULLUP);
  72. pinMode(Y, INPUT_PULLUP);
  73. pinMode(Z, INPUT_PULLUP);
  74. pinMode(START, INPUT_PULLUP);
  75.  
  76. pinMode(R, INPUT_PULLUP);
  77. pinMode(L, INPUT_PULLUP);
  78. pinMode(RLIGHT, INPUT_PULLUP);
  79.  
  80. pinMode(LEFT, INPUT_PULLUP);
  81. pinMode(RIGHT, INPUT_PULLUP);
  82. pinMode(UP, INPUT_PULLUP);
  83. pinMode(DOWN, INPUT_PULLUP);
  84.  
  85. pinMode(X1, INPUT_PULLUP);
  86. pinMode(X2, INPUT_PULLUP);
  87. pinMode(Y1, INPUT_PULLUP);
  88. pinMode(Y2, INPUT_PULLUP);
  89.  
  90. pinMode(CLEFT, INPUT_PULLUP);
  91. pinMode(CRIGHT, INPUT_PULLUP);
  92. pinMode(CUP, INPUT_PULLUP);
  93. pinMode(CDOWN, INPUT_PULLUP);
  94.  
  95. pinMode(SWITCH, INPUT_PULLUP);
  96.  
  97. //This is needed to run the code.
  98. GamecubeController1.read();
  99. }
  100.  
  101. void loop()
  102. {
  103. //This resets and establishes all the values after the controller sends them to the console and helps with initial "zeroing"
  104. int pinA = 0;
  105. int pinB = 0;
  106. int pinX = 0;
  107. int pinY = 0;
  108. int pinZ = 0;
  109. int pinSTART = 0;
  110.  
  111. int pinR = 0;
  112. int pinL = 0;
  113. int pinRLIGHT = 0;
  114.  
  115. int pinLEFT = 0;
  116. int pinRIGHT = 0;
  117. int pinUP = 0;
  118. int pinDOWN = 0;
  119.  
  120. int pinX1 = 0;
  121. int pinX2 = 0;
  122. int pinY1 = 0;
  123. int pinY2 = 0;
  124.  
  125. int pinCLEFT = 0;
  126. int pinCRIGHT = 0;
  127. int pinCUP = 0;
  128. int pinCDOWN = 0;
  129.  
  130. int pinxAxisC = 128;
  131. int pinyAxisC = 128;
  132.  
  133. int pinxAxis = 128;
  134. int xmod = 0;
  135. int pinyAxis = 128;
  136.  
  137. int rightOne = 0;
  138. int leftOne = 0;
  139. int downOne = 0;
  140.  
  141. int pinSWITCH = 0;
  142.  
  143. //This reads control stick as neutral when both left/right or up/down is pressed at the same time. Also sets parameters for the diffrent analog tilt modifiers IE: X1+X2 = X3
  144. //UPDATE: NOW CORRESPONDS TO PROPER SMASHBOX ANGLES
  145. if (digitalRead(LEFT) == HIGH && digitalRead(RIGHT) == LOW){
  146. pinxAxis = 128+86;
  147. if (digitalRead(X1) == LOW && digitalRead(X2) == HIGH)pinxAxis = X1v + 128;
  148. if (digitalRead(X1) == HIGH && digitalRead(X2) == LOW)pinxAxis = X2v + 128;
  149. if (digitalRead(X1) == LOW && digitalRead(X2) == LOW)pinxAxis = X3v + 128;
  150. rightOne = 1;
  151. }
  152. if (digitalRead(LEFT) == LOW && digitalRead(RIGHT) == HIGH){
  153. pinxAxis = 128-86;
  154. if (digitalRead(X1) == LOW && digitalRead(X2) == HIGH)pinxAxis = 128 - X1v;
  155. if (digitalRead(X1) == HIGH && digitalRead(X2) == LOW)pinxAxis = 128 - X2v;
  156. if (digitalRead(X1) == LOW && digitalRead(X2) == LOW)pinxAxis = 128 - X3v;
  157. leftOne = 1;
  158. }
  159.  
  160. if (digitalRead(DOWN) == HIGH && digitalRead(UP) == LOW){
  161. pinyAxis = 128+86;
  162. if (digitalRead(Y1) == LOW && digitalRead(Y2) == HIGH)pinyAxis = 128 + Y1v;
  163. if (digitalRead(Y1) == HIGH && digitalRead(Y2) == LOW)pinyAxis = 128 + Y2v;
  164. if (digitalRead(Y1) == LOW && digitalRead(Y2) == LOW)pinyAxis = 128 + Y3v;
  165. }
  166. if (digitalRead(DOWN) == LOW && digitalRead(UP) == HIGH){
  167. pinyAxis = 128-86;
  168. if (digitalRead(Y1) == LOW && digitalRead(Y2) == HIGH)pinyAxis = 128 - Y1v;
  169. if (digitalRead(Y1) == HIGH && digitalRead(Y2) == LOW)pinyAxis = 128 - Y2v;
  170. if (digitalRead(Y1) == LOW && digitalRead(Y2) == LOW)pinyAxis = 128 - Y3v;
  171. downOne = 1;
  172. }
  173.  
  174. //NEW: Axe Shield Drops
  175. if (digitalRead(X1) == HIGH && digitalRead(X2) == HIGH && digitalRead(Y1) == HIGH && digitalRead(Y2) == HIGH && downOne == 1 && leftOne == 1){
  176. pinxAxis = 128-80;
  177. pinyAxis = 128-78;
  178. }
  179.  
  180. if (digitalRead(X1) == HIGH && digitalRead(X2) == HIGH && digitalRead(Y1) == HIGH && digitalRead(Y2) == HIGH && downOne == 1 && rightOne == 1){
  181. pinxAxis = 128+80;
  182. pinyAxis = 128-78;
  183. }
  184.  
  185. //Reads CStick pins, same logic as controlstick values.
  186. if (digitalRead(CLEFT) == HIGH && digitalRead(CRIGHT) == LOW)pinxAxisC = 255;
  187. if (digitalRead(CLEFT) == LOW && digitalRead(CRIGHT) == HIGH)pinxAxisC = 0;
  188. if (digitalRead(CDOWN) == HIGH && digitalRead(CUP) == LOW)pinyAxisC = 255;
  189. if (digitalRead(CDOWN) == LOW && digitalRead(CUP) == HIGH)pinyAxisC = 0;
  190.  
  191. if (digitalRead(A) == LOW)pinA = 1;
  192. if (digitalRead(B) == LOW)pinB = 1;
  193. if (digitalRead(X) == LOW)pinX = 1;
  194. if (digitalRead(Y) == LOW)pinY = 1;
  195. if (digitalRead(Z) == LOW)pinZ = 1;
  196. if (digitalRead(START) == LOW)pinSTART = 1;
  197. //This is for analog shield
  198. if (digitalRead(RLIGHT) == LOW)pinRLIGHT = RLIGHTv;
  199. //This is for digital shield
  200. if (digitalRead(R) == LOW){pinR = 1; d.report.right = 174;}
  201. else { d.report.right = 0;}
  202. if (digitalRead(L) == LOW){pinL = 1; d.report.left = 174;}
  203. else { d.report.left = 0;}
  204.  
  205. if (digitalRead(SWITCH) == LOW)pinSWITCH = 1;
  206.  
  207. d.report.dup = 0;
  208. d.report.dright = 0;
  209. d.report.ddown = 0;
  210. d.report.dleft = 0;
  211.  
  212. //NEW WHEN SWITCH/BUTTON ON PIN 12 IS PRESSED/ACTIVATED SWAPS X1,X2,Y1,Y2 TO DPAD
  213. if (pinSWITCH == 1){
  214. if(digitalRead(X1) == LOW)d.report.dleft = 1;
  215. if(digitalRead(X2) == LOW)d.report.ddown = 1;
  216. if(digitalRead(Y1) == LOW)d.report.dup = 1;
  217. if(digitalRead(Y2) == LOW)d.report.dright = 1;
  218. }
  219.  
  220.  
  221.  
  222. //reports data
  223. d.report.a = pinA;
  224. d.report.b = pinB;
  225. d.report.x = pinX;
  226. d.report.y = pinY;
  227. d.report.z = pinZ;
  228. d.report.start = pinSTART;
  229. d.report.left = pinRLIGHT;
  230. d.report.r = pinR;
  231. d.report.l = pinL;
  232. d.report.xAxis = pinxAxis;
  233. d.report.yAxis = pinyAxis;
  234. d.report.cxAxis = pinxAxisC;
  235. d.report.cyAxis = pinyAxisC;
  236. //sends the complied data to console when console polls for the input
  237. GamecubeConsole.write(d);
  238.  
  239. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement