Advertisement
fire219

Arduino joystick code

Oct 13th, 2015
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. /*
  2. Petry Arcade Stick --- Arduino section
  3.  
  4. Reads inputs from joystick microswitches and sends the data out over serial (115200 baud) as a int
  5. */
  6.  
  7. // constants won't change. They're used here to
  8. // set pin numbers:
  9. const int down = 6;
  10. const int up = 7;
  11. const int left = 4;
  12. const int right = 5;
  13. const int trigger = 3;
  14.  
  15. // variables will change:
  16. int output = 0;
  17.  
  18. void setup() {
  19. Serial.begin(115200);
  20. pinMode(down, INPUT_PULLUP);
  21. pinMode(right, INPUT_PULLUP);
  22. pinMode(left, INPUT_PULLUP);
  23. pinMode(up, INPUT_PULLUP);
  24. pinMode(trigger, INPUT_PULLUP);
  25. }
  26.  
  27. void loop() {
  28. if (digitalRead(up) == LOW) {
  29. output = 1 + output;
  30. }
  31. if (digitalRead(right) == LOW) {
  32. output = 7 + output;
  33. }
  34. if (digitalRead(down) == LOW) {
  35. output = 11 + output;
  36. }
  37. if (digitalRead(left) == LOW) {
  38. output = 15 + output;
  39. }
  40. if (digitalRead(trigger) == LOW) {
  41. output = 19 + output;
  42. }
  43.  
  44. Serial.println(output);
  45.  
  46.  
  47. output = 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement