const uint8_t SPinB[] = {6, 5, 4, 3};    // S0 ... S3
const uint8_t SPinL[] = {11, 10, 9, 8};  // S0 ... S3

const int SIGB = 2; // SIG pin input for buttons
const int SIGL = 7; // SIG pin output for leds

int readMux(int channel) {
  for (int i = 0; i < 4; i++) 
    digitalWrite(SPinB[i], channel >> i & 1);

  delay(10);
  return digitalRead(SIGB);
}

void setup() {
  Serial.begin(115200);
  pinMode(SIGB, INPUT);
  pinMode(SIGL, OUTPUT);

  for (int i = 0; i < 4; i++) {
    pinMode(SPinB[i], OUTPUT);
    pinMode(SPinL[i], OUTPUT);
  }
}

void loop() {
  // Print it to the Serial Monitor
  for (int i = 0; i < 16; i++) 
    Serial.print(readMux(i));
  Serial.println();

  // Find the first pressed button
  bool found = false;
  int index = 0;
  for (int i = 0; i < 16 && !found; i++) {
    if(readMux(i) == LOW) {
      index = i;
      found = true;
    }
  }

  if(found) {
    // Found a pressed button ?
    // The diagram has the buttons in a different order, 
    // therefor it is 15-index
    writeMux(15-index);
    digitalWrite(SIGL, HIGH);
  } else {
    // Nothing found? Then turn off all leds
    // The Enable is not used, so just set the SIG to LOW.
    digitalWrite(SIGL, LOW);
  }
  delay(50);
}

void writeMux(int channel) {
  for (int i = 0; i < 4; i++) 
    digitalWrite(SPinL[i], channel >> i & 1);
}
$abcdeabcde151015202530354045505560fghijfghij
nano:12
nano:11
nano:10
nano:9
nano:8
nano:7
nano:6
nano:5
nano:4
nano:3
nano:2
nano:GND.2
nano:RESET.2
nano:0
nano:1
nano:13
nano:3.3V
nano:AREF
nano:A0
nano:A1
nano:A2
nano:A3
nano:A4
nano:A5
nano:A6
nano:A7
nano:5V
nano:RESET
nano:GND.1
nano:VIN
nano:12.2
nano:5V.2
nano:13.2
nano:11.2
nano:RESET.3
nano:GND.3
mux1:I15
mux1:I14
mux1:I13
mux1:I12
mux1:I11
mux1:I10
mux1:I9
mux1:I8
mux1:I7
mux1:I6
mux1:I5
mux1:I4
mux1:I3
mux1:I2
mux1:I1
mux1:I0
mux1:COM
mux1:S3
mux1:S2
mux1:S1
mux1:S0
mux1:EN
mux1:VCC
mux1:GND
mux2:I15
mux2:I14
mux2:I13
mux2:I12
mux2:I11
mux2:I10
mux2:I9
mux2:I8
mux2:I7
mux2:I6
mux2:I5
mux2:I4
mux2:I3
mux2:I2
mux2:I1
mux2:I0
mux2:COM
mux2:S3
mux2:S2
mux2:S1
mux2:S0
mux2:EN
mux2:VCC
mux2:GND
btn1:1.l
btn1:2.l
btn1:1.r
btn1:2.r
r1:1
r1:2
btn2:1.l
btn2:2.l
btn2:1.r
btn2:2.r
r2:1
r2:2
btn3:1.l
btn3:2.l
btn3:1.r
btn3:2.r
r3:1
r3:2
btn4:1.l
btn4:2.l
btn4:1.r
btn4:2.r
r4:1
r4:2
btn5:1.l
btn5:2.l
btn5:1.r
btn5:2.r
r5:1
r5:2
btn6:1.l
btn6:2.l
btn6:1.r
btn6:2.r
r6:1
r6:2
btn7:1.l
btn7:2.l
btn7:1.r
btn7:2.r
r7:1
r7:2
btn8:1.l
btn8:2.l
btn8:1.r
btn8:2.r
r8:1
r8:2
btn9:1.l
btn9:2.l
btn9:1.r
btn9:2.r
r9:1
r9:2
btn10:1.l
btn10:2.l
btn10:1.r
btn10:2.r
r10:1
r10:2
btn11:1.l
btn11:2.l
btn11:1.r
btn11:2.r
r11:1
r11:2
btn12:1.l
btn12:2.l
btn12:1.r
btn12:2.r
r12:1
r12:2
btn13:1.l
btn13:2.l
btn13:1.r
btn13:2.r
r13:1
r13:2
btn14:1.l
btn14:2.l
btn14:1.r
btn14:2.r
r14:1
r14:2
btn15:1.l
btn15:2.l
btn15:1.r
btn15:2.r
r15:1
r15:2
btn16:1.l
btn16:2.l
btn16:1.r
btn16:2.r
r16:1
r16:2
led1:A
led1:C
r17:1
r17:2
led2:A
led2:C
r18:1
r18:2
led3:A
led3:C
r19:1
r19:2
led4:A
led4:C
r20:1
r20:2
led5:A
led5:C
r21:1
r21:2
led6:A
led6:C
r22:1
r22:2
led7:A
led7:C
r23:1
r23:2
led8:A
led8:C
r24:1
r24:2
led9:A
led9:C
r25:1
r25:2
led10:A
led10:C
r26:1
r26:2
led11:A
led11:C
r27:1
r27:2
led12:A
led12:C
r28:1
r28:2
led13:A
led13:C
r29:1
r29:2
led14:A
led14:C
r30:1
r30:2
led15:A
led15:C
r31:1
r31:2
led16:A
led16:C
r32:1
r32:2