ArduinoJoystick

Arduino Detected jimmyd 7 Views Size: 706 bytes Posted on: Oct 5, 25 @ 11:05 AM
  1. 1#define JOY_UP 6
  2. 2#define JOY_DOWN 5
  3. 3#define JOY_LEFT 4
  4. 4#define JOY_RIGHT 3
  5. 5#define JOY_BUTTON 2
  6. 6
  7. 7int Pin[5]={JOY_BUTTON,JOY_RIGHT,JOY_LEFT,JOY_DOWN,JOY_UP};
  8. 8int State[5]={0,0,0,0,0};
  9. 9
  10. 10void setup() {
  11. 11 // Setup serical communication and wait for it to be ready
  12. 12 Serial.begin(115200);
  13. 13 while (!Serial) { ; }
  14. 14
  15. 15 // Set pins to input with internal pullup resistor
  16. 16 for (int i = 0; i < 5; i++) {
  17. 17 pinMode(Pin[i], INPUT_PULLUP);
  18. 18 }
  19. 19}
  20. 20
  21. 21void loop() {
  22. 22 // Read input states and print it to serial port
  23. 23 for (int i = 0; i < 5; i++) {
  24. 24 State[i] = digitalRead(Pin[i]);
  25. 25 Serial.print(State[i]);
  26. 26 }
  27. 27 Serial.print('\n'); // Newline to indicate all bits are sent
  28. 28}

Raw Paste

Comments 0
Login to post a comment.
  • No comments yet. Be the first.
Login to post a comment. Login or Register
We use cookies. To comply with GDPR in the EU and the UK we have to show you these.

We use cookies and similar technologies to keep this website functional (including spam protection via Google reCAPTCHA), and — with your consent — to measure usage and show ads. See Privacy.