Lost on using MUX shield

Right Now I'm now I'm trying to get an LED blinking on on of the MUX's pins. I have been able to use the example code to do so but I'm lost on how to select any one pin or set of pins.

This code is what I got from the example code. (http://mayhewlabs.com/code/Mux_Shield_DigitalOut_Example.pde)

#define CONTROL0 5    //MUX control pin 0 (S3 is connected to Arduino pin 2)
#define CONTROL1 4
#define CONTROL2 3
#define CONTROL3 2

void setup()
{
  //Set MUX control pins to output
  pinMode(CONTROL0, OUTPUT);
  pinMode(CONTROL1, OUTPUT);
  pinMode(CONTROL2, OUTPUT);
  pinMode(CONTROL3, OUTPUT);
}
  

void loop()
{

  //Since all 3 multiplexers have the same control pins, the one multiplexer data line we want to 
  //talk to should be set to output and the other two multiplexer lines should be be 'bypassed' by 
  //setting the pins to input
    
  //Turn on output to digital pin 14 (MUX 0) and turn off the other 2 multiplexer data pins
  pinMode(14, OUTPUT);
  pinMode(15, INPUT);
  pinMode(16, INPUT);
    
  //This for loop is used to scroll through the FIRST multiplexer
int i=14;
  {    
    //The following 4 commands set the correct logic for the control pins to select the desired input
    //See the Arduino Bitwise AND Reference: http://www.arduino.cc/en/Reference/BitwiseAnd
    //See the Aruino Bitshift Reference: http://www.arduino.cc/en/Reference/Bitshift
    digitalWrite(CONTROL0, (i&15)>>3); //S3
    digitalWrite(CONTROL1, (i&7)>>2);  //S2
    digitalWrite(CONTROL2, (i&3)>>1);  //S1
    digitalWrite(CONTROL3, (i&1));     //S0
    
    digitalWrite(14, HIGH);
    delay(100);
    digitalWrite(14, LOW);
    delay(100);
  }
}

Here is the code I'm trying to get working.

//Give convenient names to the control pins
#define CONTROL0 5    //MUX control pin 0 (S3 is connected to Arduino pin 2)
#define CONTROL1 4
#define CONTROL2 3
#define CONTROL3 2

void setup()
{
  //Set MUX control pins to output
  pinMode(CONTROL0, OUTPUT);
  pinMode(CONTROL1, OUTPUT);
  pinMode(CONTROL2, OUTPUT);
  pinMode(CONTROL3, OUTPUT);
}

void loop() {
  pinMode(1, OUTPUT);
  pinMode(7, INPUT);
  pinMode(0, INPUT);
  
  int i=1; 
{  
    //The following 4 commands set the correct logic for the control pins to select the desired input
    //See the Arduino Bitwise AND Reference: http://www.arduino.cc/en/Reference/BitwiseAnd
    //See the Aruino Bitshift Reference: http://www.arduino.cc/en/Reference/Bitshift
    digitalWrite(CONTROL0, (i&15)>>3); //S3
    digitalWrite(CONTROL1, (i&7)>>2);  //S2
    digitalWrite(CONTROL2, (i&3)>>1);  //S1
    digitalWrite(CONTROL3, (i&1));     //S0
  
  digitalWrite(1, HIGH);
  delay(400);
  digitalWrite(1, LOW);
  delay(200);
}
}

If I input in the right pin number for pin 14 M0 it works. I have found with the code from the example code 0, 16, and 8 are interchangeable. I have a feeling that these three lines have something to do with it.

    digitalWrite(CONTROL0, (i&15)>>3); //S3
    digitalWrite(CONTROL1, (i&7)>>2);  //S2
    digitalWrite(CONTROL2, (i&3)>>1);  //S1
    digitalWrite(CONTROL3, (i&1));     //S0

But I can't find the relation. How does one pick which pin from with group to use as I/O etc?

Look at the example and you will see that no matter which of the 16 lines on MUX 0 it wants to light up, it turns on output pin 14.

When you changed the MUX 0, Pin 14 example to try MUX 0, Pin 1 you accidentally changed the "digitalWrite(14,HIGH)" to "digitalWrite(1,HIGH)". Since the input to MUX 0 is from Arduino Pin 14 (NOT Arduino Pin 1) you don't get the expected output.

Perhaps if you defined names for the three output pins (14, 15, and 16) you could keep them straight more easily:

const int MUX0_Pin = 14;
const int MUX1_Pin = 15;
const int MUX2_Pin = 16;

OK, So factored in the constants and with M0 pin 14 I have a slowly blinking LED. How can I do the same thing on pin 1?

Well, you were able to control the LED on MUX 0 PIN 14 by setting the MUX address lines to 14 and setting the MUX 0 data line to HIGH and LOW.

To control an LED on MUX 0 PIN 1, set the MUX address lines to 1 and set the MUX 0 data line to HIGH and LOW.

Which line is the MUX address line? And which one is the MUX 0 data line?

The MUX address lines are the ones called CONTROL0-CONTROL3. The MUX 0 data line is Arduino pin 14.

You should look at the schematic for your Mux Shield and read the datasheet for the Mux chips.

Got it! or at least I'm pretty sure I do. So I found the MUX chip data sheet; it has a truth table, and according to the truth table in order to select pin 1, all but S0 need to read false. So I used:

    digitalWrite(CONTROL0, (i&0)); //S3
    digitalWrite(CONTROL1, (i&8));  //S2
    digitalWrite(CONTROL2, (i&12));  //S1
    digitalWrite(CONTROL3, (i&1));     //S0

To get that result. My LED now blinks :grin:. Though I'm a little lost on why the example code used bit shifting when it could just use 14 three times on the MUX address line.