Advertisement
Guest User

Helder board + battery - USB v2

a guest
Jul 8th, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. /* pinouts:
  2. * A0: analog y axis
  3. * A1: analog x axis
  4. * A2: ADC5
  5. * A3: ADC4
  6. * A4: ADC1
  7. * A5: ADC0
  8. * 9: R1
  9. * 10: R2
  10. * 11: L2
  11. */
  12.  
  13. #include "HID-Project.h"
  14.  
  15. #define NUM_BUTTONS 14
  16.  
  17. #define BTN_UP 0
  18. #define BTN_DOWN 1
  19. #define BTN_LEFT 2
  20. #define BTN_RIGHT 3
  21. #define BTN_A 4
  22. #define BTN_START 5
  23. #define BTN_Y 6
  24. #define BTN_L1 A1
  25. #define BTN_X 8
  26. #define BTN_R1 A0
  27. //#define BTN_R1 9
  28. //#define BTN_R2 10
  29. //#define BTN_L2 11
  30. #define BTN_B 12
  31. #define BTN_SELECT 13
  32.  
  33. const int battPin = A2;
  34. const int chargingPin = A3;
  35. const int chargedPin = A4;
  36. //const int shutdownPin = A5;
  37. const int redPin = 9;
  38. const int greenPin = 10;
  39. const int bluePin = 11;
  40. const float lowBattVoltage = 0; //FIX
  41. const float shutdownVoltage = 0; //FIX
  42. float voltage;
  43. int charging;
  44. int charged;
  45.  
  46. void setup() {
  47. for (int i = 0; i < NUM_BUTTONS; i++) {
  48. pinMode(i, INPUT_PULLUP);
  49. }
  50. pinMode(A0, INPUT_PULLUP);
  51. pinMode(A1, INPUT_PULLUP);
  52.  
  53. pinMode(battPin, INPUT);
  54. pinMode(chargingPin, INPUT);
  55. pinMode(chargedPin, INPUT);
  56. // pinMode(shutdownPin, OUTPUT);
  57. pinMode(redPin, OUTPUT);
  58. pinMode(greenPin, OUTPUT);
  59. pinMode(bluePin, OUTPUT);
  60. Serial.begin(9600);
  61.  
  62. // Sends a clean report to the host. This is important on any Arduino type.
  63. Gamepad.begin();
  64. Keyboard.begin();
  65. }
  66.  
  67. void loop() {
  68.  
  69. //Battery monitor
  70. /* voltage = analogRead(battPin) * (5.00 / 1023.00);
  71. Serial.println(voltage);
  72. charging = digitalRead(chargingPin);
  73. charged = digitalRead(chargedPin);
  74.  
  75. if (voltage <= shutdownVoltage) && (charging == LOW) {
  76. Keyboard.press(KEY_LEFT_CTRL);
  77. Keyboard.press(KEY_ESC);
  78. delay(100);
  79. Keyboard.releaseAll();
  80. }
  81.  
  82. if (charged == HIGH) {
  83. Serial.println("charged");
  84. analogWrite(redPin, 255);
  85. analogWrite(greenPin, 255);
  86. analogWrite(bluePin, 245);
  87. } else if (charging == LOW) {
  88. Serial.println("charging");
  89. analogWrite(redPin, 220);
  90. analogWrite(greenPin, 218);
  91. analogWrite(bluePin, 248);
  92. } else if (voltage <= lowBattVoltage) {
  93. Serial.println("lowbatt");
  94. analogWrite(redPin, 245);
  95. analogWrite(greenPin, 255);
  96. analogWrite(bluePin, 255);
  97. } else {
  98. Serial.println("power");
  99. analogWrite(redPin, 255);
  100. analogWrite(greenPin, 245);
  101. analogWrite(bluePin, 255);
  102. }
  103. */
  104. //Gamepad
  105. bool down = !digitalRead(BTN_DOWN);
  106. bool up = !digitalRead(BTN_UP);
  107. bool left = !digitalRead(BTN_LEFT);
  108. bool right = !digitalRead(BTN_RIGHT);
  109.  
  110. Gamepad.dPad1(GAMEPAD_DPAD_CENTERED);
  111.  
  112. if (down) {
  113. Gamepad.dPad1(GAMEPAD_DPAD_DOWN);
  114. if (left) {
  115. Gamepad.dPad1(GAMEPAD_DPAD_DOWN_LEFT);
  116. } if (right) {
  117. Gamepad.dPad1(GAMEPAD_DPAD_DOWN_RIGHT);
  118. }
  119. } else if (up) {
  120. Gamepad.dPad1(GAMEPAD_DPAD_UP);
  121. if (left) {
  122. Gamepad.dPad1(GAMEPAD_DPAD_UP_LEFT);
  123. } if (right) {
  124. Gamepad.dPad1(GAMEPAD_DPAD_UP_RIGHT);
  125. }
  126. } else if (left) {
  127. Gamepad.dPad1(GAMEPAD_DPAD_LEFT);
  128. } else if (right) {
  129. Gamepad.dPad1(GAMEPAD_DPAD_RIGHT);
  130. }
  131.  
  132. for (int i = BTN_A; i < NUM_BUTTONS; i++) {
  133. if (!digitalRead(i)) {
  134. Gamepad.press(i);
  135. } else {
  136. Gamepad.release(i);
  137. }
  138. }
  139.  
  140. if (!digitalRead(A0)) {
  141. Gamepad.press(A0);
  142. } else {
  143. Gamepad.release(A0);
  144. }
  145.  
  146. if (!digitalRead(A1)) {
  147. Gamepad.press(A1);
  148. } else {
  149. Gamepad.release(A1);
  150. }
  151.  
  152. Gamepad.write();
  153. delay(10);
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement