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

PasteIT is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.