Advertisement
Guest User

Guitar Controller Code

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