#define JOY_UP 6 #define JOY_DOWN 5 #define JOY_LEFT 4 #define JOY_RIGHT 3 #define JOY_BUTTON 2 int Pin[5]={JOY_BUTTON,JOY_RIGHT,JOY_LEFT,JOY_DOWN,JOY_UP}; int State[5]={0,0,0,0,0}; void setup() { // Setup serical communication and wait for it to be ready Serial.begin(115200); while (!Serial) { ; } // Set pins to input with internal pullup resistor for (int i = 0; i < 5; i++) { pinMode(Pin[i], INPUT_PULLUP); } } void loop() { // Read input states and print it to serial port for (int i = 0; i < 5; i++) { State[i] = digitalRead(Pin[i]); Serial.print(State[i]); } Serial.print('\n'); // Newline to indicate all bits are sent }