I'm using a multiplexer to read 8 different slide potentiometers, but it's acting very weird. I have two multiplexers for 16 total pots, and my first 8 (mux 1) are working correctly but the second mux has some weird behaviour. When I select only one mux pin and read it in the loop, the values are what I expect, however, when I read pot 1 and then pot2 the value of pot 1 follows the value of pot2, as if the mux is not switching from pot1. It continues in a pattern of 2's, (eg 1 follows 2, 3 follows 4, 5 follows 6 etc) and this is leading me to believe that the leading bit for the mux select is being dropped somewhere, but I cannot find where. To explain, to select pot 0 i send bit 000, 1: 100: 2: 010, 3:110, but I think it is somehow only sending 00, 00, 10, 10, and leaving the first bit pulled low. I am almost certain my physical wiring is correct, but I could be wrong. My mux select function is :
void selectMuxPin(byte pin, bool mux2) {
if(!mux2){
for (int i = 0; i < 3; i++) {
if (pin & (1 << i))
digitalWrite(selectPins1[i], HIGH);
else
digitalWrite(selectPins1[i], LOW);
}
}
else if(mux2){
for (int i = 0; i < 3; i++) {
if (pin & (1 << i)){
digitalWrite(selectPins2[i], HIGH);
}
else{
digitalWrite(selectPins2[i], LOW);
}
}
}
}
And here is how I'm reading the pins (in a test function, not actual implementation).
Serial.print("\n ");
selectMuxPin(0, true);
Serial.print(analogRead(A1));
Serial.print(" ");
selectMuxPin(1, true);
Serial.print(analogRead(A1));
etc. etc.
edit - using sparkfun pro micro, pin 3, 4 and 5 are my mux select pins and a1 the z pin.