Analog Multiplexer CD406BE

I used this person’s diagram and code to get started: http://www.tigoe.com/pcomp/code/arduinowiring/540/

I started with a set up using 16 LEDs. It worked, but there were clearly places were the circuit wasn’t wired correctly and there was too much stuff on my little breadboard for me to see what was happening. In this video I am using Mr. Igeo’s code.

I switched to a setup of four RGB LEDs. The multiplexer has enough outputs for 5, but only 4 would fit on the board. This video shows Mr. Igeo’s code again, this time with the RGB LEDs.

It took me quite a bit of looking at Igeo’s code and comparing it to the logic table on the data sheet to figure out how to control a single on/off. Igeo’s code uses some niffty short cuts to cycle through the LEDs, but I opted to rewrite my code out to make sure that I understood what was going on. This video shows some patterns I tried to make. LED four still isn’t behaving quite right, as you can tell, but so far I haven’t been able to figure out where the hang up is.

Issues

It also took me awhile to realize that while the multiplexer has 16 outputs, only one of those can be switched on at any one time, since each output is controlled by a combination of the four inputs. I found this extremely frustrating, since the changing the color of the RGB LEDs is the fun part. I tried to get around this by blinking the LED’s really fast.

The other thing I ran into was with fading the LEDs. Igeo uses a for loop to control the common pin on the multiplexer in order to fade in the lights. I wanted to fade the lights while changing the color, but I could not think of a way to do that without being able to turn two pins on at once (or writing way more code than I was willing to write). I also could not think of a way to move the fade from one pin to another without doing it manually.

I can see how this would be useful if you were running out of pins, but it seems really limiting not to be able to turn more than one on at once. Am I missing something?

Code

/*
Multiplexer output example
Controls four RGB LEDs using a CD4067B multiplexer.

created 25 Mar 2014
by Natasha Lewandrowski

Based on a sketch
created 21 May 2009
by Tom Igoe
http://www.tigoe.net/pcomp/code/category/arduinowiring/540 for more

The circuit:
* CD4067 multiplexer attached as follows:
– address pin A: digital I/O 2
– address pin B: digital I/O 3
– address pin C: digital I/O 4
– address pin D: digital I/O 5
– input pin: digital I/O pin 6
– LEDs attached from each of the CD4067’s output channels
to ground

m0 = LED 1 red
m1 = lED 1 green
m2 = LED 1 blue
m3 = LED 2 red
m4 = lED 2 green
m5 = LED 2 blue
m6 = LED 3 red
m7 = lED 3 green
m8 = LED 3 blue
m9 = LED 4 red
m10 = lED 4 green
m11 = LED 4 blue
m12 = not used
m13 = not used
m14 = not used
m15 = not used

*/

//declare the mux channel pins
const int channelA = 2;
const int channelB = 3;
const int channelC = 4;
const int channelD = 5;

// declare the common output pin channel (mux’s input)
//declare the inhibitPin
const int outputPin = 6;
const int inhibitPin =7;

//this will be used to control the brightness of the output
//int brightness = 0;

int delayTime = 1;

void setup() {
// set up all pins as output:
pinMode(channelA, OUTPUT);
pinMode(channelB, OUTPUT);
pinMode(channelC, OUTPUT);
pinMode(channelD, OUTPUT);
pinMode(outputPin, OUTPUT);
pinMode(inhibitPin, OUTPUT);

digitalWrite(channelA, LOW);
digitalWrite(channelB, LOW);
digitalWrite(channelC, LOW);
digitalWrite(channelD, LOW);
digitalWrite(inhibitPin,LOW);

}

void loop() {

analogWrite(outputPin, 255);

RGBcycle();
delay(1000);
digitalWrite(inhibitPin,HIGH);

greenPattern1();
delay(1000);
digitalWrite(inhibitPin,HIGH);

rainbow();
delay(1000);
digitalWrite(inhibitPin,HIGH);

rainbow2();
delay(1000);
digitalWrite(inhibitPin,HIGH);

}

//pattern functions==============

void RGBcycle(){
int rgbDelay = 50;
//LED1
//analogWrite(outputPin, 10);
led1red();
delay(rgbDelay);
digitalWrite (inhibitPin, HIGH);

//analogWrite(outputPin, 20);
led1green();
delay(rgbDelay);
digitalWrite (inhibitPin, HIGH);

//analogWrite(outputPin, 30);
led1blue();
delay(rgbDelay);
digitalWrite (inhibitPin, HIGH);

//LED2
//analogWrite(outputPin, 40);
led2red();
delay(rgbDelay);
digitalWrite (inhibitPin, HIGH);

//analogWrite(outputPin, 50);
led2green();
delay(rgbDelay);
digitalWrite (inhibitPin, HIGH);

//analogWrite(outputPin, 60);
led2blue();
delay(rgbDelay);
digitalWrite (inhibitPin, HIGH);

//LED3
//analogWrite(outputPin, 70);
led3red();
delay(rgbDelay);
digitalWrite (inhibitPin, HIGH);

//analogWrite(outputPin, 80);
led3green();
delay(rgbDelay);
digitalWrite (inhibitPin, HIGH);

//analogWrite(outputPin, 90);
led3blue();
delay(rgbDelay);
digitalWrite (inhibitPin, HIGH);

//LED4
//analogWrite(outputPin, 100);
led4red();
delay(rgbDelay);
digitalWrite (inhibitPin, HIGH);

//analogWrite(outputPin, 110);
led4green();
delay(rgbDelay);
digitalWrite (inhibitPin, HIGH);

//analogWrite(outputPin, 120);
led4blue();
delay(rgbDelay);
digitalWrite (inhibitPin, HIGH);

}

void greenPattern1(){
//int x=10;
for (int brightness = 0; brightness < 256; brightness++) {
analogWrite(outputPin, brightness);
delay(5);

led1green();
delay(delayTime);

led2green();
delay(delayTime);

led3green();
delay(delayTime);

led4green();
delay(delayTime);
}

}

void rainbow(){

for (int brightness = 0; brightness < 256; brightness++) {
analogWrite(outputPin, brightness);
delay(5);

led1red();
delay(delayTime);

led2red();
delay(delayTime);

//led3red();
//delay(delayTime);

//led4red();
//delay(delayTime);

//led1green();
//delay(delayTime);

led2green();
delay(delayTime);

led3green();
delay(delayTime);

led3blue();
delay(delayTime);

led4green();
delay(delayTime);

led4blue();
delay(delayTime);
}
}

void rainbow2(){

led1red();
delay(delayTime);

led2red();
delay(delayTime);

led3red();
delay(delayTime);

led4red();
delay(delayTime);
led1green();
delay(delayTime);

led2green();
delay(delayTime);

led3green();
delay(delayTime);

led4green();
delay(delayTime);
led1blue();
delay(delayTime);

led2blue();
delay(delayTime);

led3blue();
delay(delayTime);

led4blue();
delay(delayTime);

}

//pins==============

//m0
void led1red (){
digitalWrite(channelA, LOW);
digitalWrite(channelB, LOW);
digitalWrite(channelC, LOW);
digitalWrite(channelD, LOW);
digitalWrite(inhibitPin,LOW);
}

//m1
void led1green(){
digitalWrite(channelA, HIGH);
digitalWrite(channelB, LOW);
digitalWrite(channelC, LOW);
digitalWrite(channelD, LOW);
digitalWrite(inhibitPin,LOW);
}

//m2
void led1blue(){
digitalWrite(channelA, LOW);
digitalWrite(channelB, HIGH);
digitalWrite(channelC, LOW);
digitalWrite(channelD, LOW);
digitalWrite(inhibitPin,LOW);
}

//m3
void led2red (){
digitalWrite(channelA, HIGH);
digitalWrite(channelB, HIGH);
digitalWrite(channelC, LOW);
digitalWrite(channelD, LOW);
digitalWrite(inhibitPin,LOW);
}

//m4
void led2green(){
digitalWrite(channelA, LOW);
digitalWrite(channelB, LOW);
digitalWrite(channelC, HIGH);
digitalWrite(channelD, LOW);
digitalWrite(inhibitPin,LOW);
}

//m5
void led2blue(){
digitalWrite(channelA, HIGH);
digitalWrite(channelB, LOW);
digitalWrite(channelC, HIGH);
digitalWrite(channelD, LOW);
digitalWrite(inhibitPin,LOW);
}

//m6
void led3red (){
digitalWrite(channelA, LOW);
digitalWrite(channelB, HIGH);
digitalWrite(channelC, HIGH);
digitalWrite(channelD, LOW);
digitalWrite(inhibitPin,LOW);
}

//m7
void led3green(){
digitalWrite(channelA, HIGH);
digitalWrite(channelB, HIGH);
digitalWrite(channelC, HIGH);
digitalWrite(channelD, LOW);
digitalWrite(inhibitPin,LOW);
}

//m8
void led3blue(){
digitalWrite(channelA, LOW);
digitalWrite(channelB, LOW);
digitalWrite(channelC, LOW);
digitalWrite(channelD, HIGH);
digitalWrite(inhibitPin,LOW);
}

//m9
void led4red (){
digitalWrite(channelA, HIGH);
digitalWrite(channelB, LOW);
digitalWrite(channelC, LOW);
digitalWrite(channelD, HIGH);
digitalWrite(inhibitPin,LOW);
}

//m10
void led4green(){
digitalWrite(channelA, LOW);
digitalWrite(channelB, HIGH);
digitalWrite(channelC, LOW);
digitalWrite(channelD, HIGH);
digitalWrite(inhibitPin,LOW);
}

//m11
void led4blue(){
digitalWrite(channelA, HIGH);
digitalWrite(channelB, HIGH);
digitalWrite(channelC, LOW);
digitalWrite(channelD, HIGH);
digitalWrite(inhibitPin,LOW);
}

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s