Hello everyone.
I am new in using multiplexers. I am trying to find a way to send data (voltage) to a specific output using the least pins as possible in Arduino. I know that using multiplexers can do only one output, and I am happy with that, but I would like to know if there is a way to sync or connect another multiplexer which would work independently but using the same pins of the Arduino.
For instance, in the attached image you can see 9 red LEDs, which I am able to control individually just fine. Let's say that I want the first red LED (C0) to turn on, but I would like to turn, for example, the last yellow LED (C8) simultaneously.
I have done some research but there is not much information about this, which makes me believe that is simply not possible, but I guess it's worth to give it a shot and ask to experienced people.
I got the following code from another forum, but it seems to work fine for using only one multiplexer.
const int SIG = 2;
const int controlPin[4] = {3, 4, 5, 6}; // 4 pins used for binary output
const int muxTable[16][4] = {
{0, 0, 0, 0}, // 1
{0, 0, 0, 1}, // 2
{0, 0, 1, 0}, // 3
{0, 0, 1, 1}, // 4
{1, 0, 0, 0}, // 5
{1, 0, 0, 1}, // 6
{1, 0, 1, 0}, // 7
{1, 0, 1, 1}, // 8
{0, 1, 0, 0}, // 9
{0, 1, 0, 1}, // 10
{0, 1, 1, 0}, // 11
{0, 1, 1, 1}, // 12
{1, 1, 0, 0}, // 13
{1, 1, 0, 1}, // 14
{1, 1, 1, 0}, // 15
{1, 1, 1, 1} // 16
};
void setup() {
for(int i=0; i<4; i++) {
pinMode(controlPin[i], OUTPUT);
digitalWrite(controlPin[i], HIGH);
}
pinMode(SIG, OUTPUT);
digitalWrite(SIG, HIGH);
Serial.begin(9600);
}
void loop() {
for(int i=0; i<9; i++){
channelControl(i);
delay(1000);
}
Serial.println("===============");
}
void channelControl(int relayChannel)
{
digitalWrite(controlPin[0], muxTable[relayChannel][0]);
digitalWrite(controlPin[1], muxTable[relayChannel][1]);
digitalWrite(controlPin[2], muxTable[relayChannel][2]);
digitalWrite(controlPin[3], muxTable[relayChannel][3]);
Serial.print(relayChannel);
Serial.print (": ");
Serial.print(muxTable[relayChannel][0]);
Serial.print(muxTable[relayChannel][1]);
Serial.print(muxTable[relayChannel][2]);
Serial.println(muxTable[relayChannel][3]);
}
Thank you!!
Arturo