Advertisement
Guest User

Untitled

a guest
Jan 6th, 2016
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1.  
  2. #include "UnoJoy.h"
  3.  
  4. void setup(){
  5. setupPins();
  6. setupUnoJoy();
  7. }
  8.  
  9. void loop(){
  10.  
  11. dataForController_t controllerData = getControllerData();
  12.  
  13. setControllerData(controllerData);
  14. }
  15. void setupPins(void){
  16. // Set all the digital pins as inputs
  17. // with the pull-up enabled, except for the
  18. // two serial line pins
  19.  
  20. for (int i = 2; i <= 12; i++){
  21. pinMode(i, INPUT);
  22. digitalWrite(i, HIGH);
  23. }
  24. pinMode(A4, INPUT);
  25. digitalWrite(A4, HIGH);
  26. pinMode(A5, INPUT);
  27. digitalWrite(A5, HIGH);
  28. }
  29.  
  30. dataForController_t getControllerData(void){
  31.  
  32. // Set up a place for our controller data
  33. // Use the getBlankDataForController() function, since
  34. // just declaring a fresh dataForController_t tends
  35. // to get you one filled with junk from other, random
  36. // values that were in those memory locations before
  37. dataForController_t controllerData = getBlankDataForController();
  38. // Since our buttons are all held high and
  39. // pulled low when pressed, we use the "!"
  40. // operator to invert the readings from the pins
  41. controllerData.triangleOn = !digitalRead(2);
  42. controllerData.circleOn = !digitalRead(3);
  43. controllerData.squareOn = !digitalRead(4);
  44. controllerData.crossOn = !digitalRead(5);
  45. controllerData.dpadUpOn = !digitalRead(6);
  46. controllerData.dpadDownOn = !digitalRead(7);
  47. controllerData.dpadLeftOn = !digitalRead(8);
  48. controllerData.dpadRightOn = !digitalRead(9);
  49. controllerData.l1On = !digitalRead(10);
  50. controllerData.r1On = !digitalRead(11);
  51. controllerData.selectOn = !digitalRead(12);
  52. controllerData.startOn = !digitalRead(A4);
  53. controllerData.homeOn = !digitalRead(A5);
  54.  
  55.  
  56. // Set the analog sticks
  57. // Since analogRead(pin) returns a 10 bit value,
  58. // we need to perform a bit shift operation to
  59. // lose the 2 least significant bits and get an
  60. // 8 bit number that we can use
  61. controllerData.leftStickX = analogRead(A0) >> 2;
  62. controllerData.leftStickY = analogRead(A1) >> 2;
  63. controllerData.rightStickX = analogRead(A2) >> 2;
  64. controllerData.rightStickY = analogRead(A3) >> 2;
  65. // And return the data!
  66. return controllerData;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement