   pinMode(DEMUX_SELECT_2,OUTPUT);
   pinMode(DEMUX_SELECT_3,OUTPUT);
   pinMode(13, OUTPUT);
-  digitalWrite(DEMUX_SELECT_1, bitRead(4,0));
-  digitalWrite(DEMUX_SELECT_2, bitRead(4,1));
-  digitalWrite(DEMUX_SELECT_3, bitRead(4,2));
+  for(int i=0;i<8;i++) {
+    pinMode(READ_MUX_PINS[i], INPUT);
+  }
   Serial.begin(9600);
   Serial1.begin(31250);
 }

bool gate = false;

void loop() {
  int i,j;
  for(i=0;i<8;i++) {
    digitalWrite(WRITE_SELECT_1,bitRead(i,0));
    digitalWrite(WRITE_SELECT_2,bitRead(i,1));
    digitalWrite(WRITE_SELECT_3,bitRead(i,2));
    for(j=0;j<8;j++) {
      checkMidi();
      if(i<j) {
        digitalWrite(READ_SELECT_1,bitRead(j,0));
        digitalWrite(READ_SELECT_2,bitRead(j,1));
        digitalWrite(READ_SELECT_3,bitRead(j,2));
        if(digitalRead(READ_MUX_1)==HIGH) {
          Serial.print(i);
          Serial.print("-");
          Serial.print(j);
          Serial.print("\n");
        }
      }
    }
  }
  //checkMidi();
  for(byte i = 0; i < 0; i ++) {
    checkMidi();

const int READ_SELECT_3 = 5;

// pins for reading from multiplexers
const int READ_MUX_PINS[] = {22, 23, 24, 25, 26, 27, 28, 29};

// pins for selecting demux channel for writing
const int WRITE_SELECT_1 = 10;
