bool getMux(uint8_t pin)
{
  digitalWrite(7, bitRead(pin, 0));
  digitalWrite(6, bitRead(pin, 1));
  digitalWrite(5, bitRead(pin, 2));
  digitalWrite(4, bitRead(pin, 3));

  delay(100);
  return !digitalRead(3);
}

void setup()
{
  Serial.begin(9600);

  pinMode(7, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(3, INPUT_PULLUP);
}

void loop()
{
  for (uint16_t i = 0; i < 16; i++)
  {
    if (getMux(i))
    {
      Serial.println(i);
    }
  }
}