taj1994

Current Guitar Code

Aug 14th, 2022
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include <Joystick.h>
  2. #define joyX A0
  3.  
  4. Joystick_ Joystick;
  5.  
  6. void setup() {
  7. // Initialize Button Pins
  8. pinMode(0, INPUT_PULLUP);
  9. pinMode(1, INPUT_PULLUP);
  10. pinMode(2, INPUT_PULLUP);
  11. pinMode(3, INPUT_PULLUP);
  12. pinMode(4, INPUT_PULLUP);
  13. pinMode(5, INPUT_PULLUP);
  14. pinMode(6, INPUT_PULLUP);
  15. pinMode(7, INPUT_PULLUP);
  16. pinMode(8, INPUT_PULLUP);
  17. pinMode(9, INPUT_PULLUP);
  18. pinMode(10, INPUT_PULLUP);
  19. Joystick.setXAxisRange(0, 1023);
  20.  
  21. // Initialize Joystick Library
  22. Joystick.begin();
  23. }
  24.  
  25. // Constant that maps the phyical pin to the joystick button.
  26. const int pinToButtonMap = 0;
  27.  
  28. // Last state of the button
  29. int lastButtonState[11] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  30.  
  31. void loop() {
  32.  
  33. // Read pin values
  34. for (int index = 0; index <= 10; index++)
  35. {
  36. int currentButtonState = !digitalRead(index + pinToButtonMap);
  37. if (currentButtonState != lastButtonState[index])
  38. {
  39. Joystick.setButton(index, currentButtonState);
  40. lastButtonState[index] = currentButtonState;
  41. }
  42. }
  43.  
  44. Joystick.setXAxis(analogRead(A0));
  45.  
  46. delay(10);
  47. }
Add Comment
Please, Sign In to add comment