I'm attempting to use the multiplexer setup in this article with my Arduino Uno to control the output of LED's, as a way to fully understand the principles of multiplexing.
I'm working to modify the code in the article to switch from reading potentiometer values to writing voltage values to the LED's.
Below is the modified sketch; the biggest modified change is the loop in the writeMux
function:
//Mux control pins
int s0 = 8;
int s1 = 9;
int s2 = 10;
int s3 = 11;
//Mux in "SIG" pin
int SIG_pin = 3;
//Voltage value to write to the LEDs
int testValue = 255;
void setup(){
pinMode(s0, OUTPUT);
pinMode(s1, OUTPUT);
pinMode(s2, OUTPUT);
pinMode(s3, OUTPUT);
pinMode(SIG_pin, OUTPUT);
digitalWrite(s0, LOW);
digitalWrite(s1, LOW);
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
}
void loop(){
for(int i = 0; i < 9 ; i ++){
delay(1000);
writeMux(i);
}
}
int writeMux(int channel){
int controlPin[] = {s0, s1, s2, s3};
int muxChannel[10][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
};
//loop through the 4 sig
for(int i = 0; i < 4; i ++){
digitalWrite(controlPin[i], muxChannel[channel][i]);
}
//read the value at the SIG pin
analogWrite(testValue, SIG_pin);
//return the value
return 0;
}
Below is a photo of my circuit:
However, none of the LED's light up.
I'm fairly certain that this is more of a problem with the code rather than the circuit...any advice is appreciated!