Hello everyone,
I am planning to do a board game with RGB LEDs, I've installed everything using only 4 RGB LEDs, however I want to use more (about 25 RGB LEDs), and each one has 3 output pins for R, G and B.
So in order to do that I am using 16 channel analog multiplexer.
I never used a multiplexer, and I got the code online, I tried to light up one RGB LED, but it's not working properly. I'm not sure what I'm doing wrong. As far as I know, I should get the right channel of the pin with s0, s1, s2 & s3 then write the value to sig.
At first the RGB did not light up, then I put delay(250), and it started lighting up each color separately (R then delay by 250 and G ... ).
this is the code:
int s3 = 6;
int s2 = 7;
int s1 = 8;
int s0 = 9;
int muxChannel[16][4]={
{0,0,0,0}, //channel 0
{1,0,0,0}, //channel 1
{0,1,0,0}, //channel 2
{1,1,0,0}, //channel 3
{0,0,1,0}, //channel 4
{1,0,1,0}, //channel 5
{0,1,1,0}, //channel 6
{1,1,1,0}, //channel 7
{0,0,0,1}, //channel 8
{1,0,0,1}, //channel 9
{0,1,0,1}, //channel 10
{1,1,0,1}, //channel 11
{0,0,1,1}, //channel 12
{1,0,1,1}, //channel 13
{0,1,1,1}, //channel 14
{1,1,1,1} //channel 15
};
int controlPin[] = {s0, s1, s2, s3};
int sig = 5;
int led3[6] = {8, 9, 10, 0, 0, 0};
void setup()
{
pinMode(s0, OUTPUT);
pinMode(s1, OUTPUT);
pinMode(s2, OUTPUT);
pinMode(s3, OUTPUT);
digitalWrite(s0, LOW);
digitalWrite(s1, LOW);
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
pinMode(sig, OUTPUT);
Serial.begin(9600);
}
void loop()
{ setCol(led3, 150, 0, 0);
delay(100);
}
void setCol(int* led, int r, int g, int b) {
for(int i = 0; i < 4; i ++){
digitalWrite(controlPin[i], muxChannel[led[0]][i]);
}
analogWrite(sig, r);
delay(250);
for(int i = 0; i < 4; i ++){
digitalWrite(controlPin[i], muxChannel[led[1]][i]);
}
analogWrite(sig, g);
delay(250);
for(int i = 0; i < 4; i ++){
digitalWrite(controlPin[i], muxChannel[led[2]][i]);
}
analogWrite(sig, b);
delay(250);
}
how do I make this work, how can I connect RGB LED with this multiplexer properly?
Tried hours looking online but no luck.
Thank you