#include Joystick_ Joystick; const byte BR[3] = {1,2,3}; // Button array rows const byte BC[3] = {4,5,6}; // Button array columns const byte BK[3][3] = {{1,2,3},{4,5,6},{7,8,9}}; // Buttons controller keys const bool Bstate[3][3] = {{0,0,0},{0,0,0},{0,0,0}}; // Buttons state const byte RE[6][2] = {{7,8},{9,10},{11,12},{13,14},{15,16},{17,18}}; // Rotary encoders pins {A,B} const byte REK[6][2] = {{10,11},{12,13},{14,15},{16,17},{18,19},{20,21}}; // Rotary encoders keys {-,+} const bool REstate[6][2] = {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}; // Rotary encoders state void setup() { for(int i=0; i<6; i++) { pinMode(REl[i], INPUT_PULLUP); pinMode(REr[i], INPUT_PULLUP); } for(int i=0; i<6; i++) { pinMode(BR[i], INPUT); pinMode(BC[i], INPUT_PULLUP); } Joystick.begin() } void readMatrix() { for (int i=0; i<3; i++) { pinMode(BC[i], OUTPUT); digitalWrite(BC[i], LOW); for (int j=0; j<3; j++) { pinMode(BR[j], INPUT_PULLUP); int state = digitalRead(BR[j]); if (state != Bstate[j][i]) { Joystick.setButton(BK[j][i], state); Bstate[j][i] = state; } pinMode(BR[j], INPUT); } pinMode(BC[i], INPUT); } } void readEncoders() { } void loop() { readMatrix(); }