Hi,
i've used this 4051 many times before with the same code and it has always worked fine.
until today, i finished the wiring on my latest project and only half of the pots work.
i've checked the wires and i cant seem to find the problem there.
but maybe somebody had had this problem before so i thought i should ask.
what happens is that when i turn pot 1, it will show the exact same value in the serial monitor for pot 1 and pot 4. pot 4 doesn't work.
if i turn pot 2, it will show the exact same value in the serial monitor for pot 2 and pot 3. pot 3 doens't work.
any ideas?
int MuxPin1=2;
int MuxPin2=4;
int MuxPin3=3;
int AnaInPin1=0;
int AnaInPin2=1;
//Declare variables
int MuxVal1 = 0;
int MuxVal2 = 0;
int MuxVal3 = 0;
int BinVal = 0;
int N = 0;
//BinPat is used for figuring out the High / Low (1/0) values of the MUX control pins
int BinPat [] = {000, 1, 10, 11, 100, 101, 110, 111};
//The PotValues array is used for storing the 16 vlues read from the potentiometers
int PotValues [] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
void setup()
{
//Initialize digital pins and serial communication speed
pinMode(MuxPin1, OUTPUT);
pinMode(MuxPin2, OUTPUT);
pinMode(MuxPin3, OUTPUT);
Serial.begin(9600);
}
void loop() {
readPotValues();
sendPotValues();
delay (10);
}
void readPotValues()
{
for (N=0; N<=7; N++)
{
BinVal = BinPat[N];
MuxVal1 = BinVal & 0x01;
MuxVal2 = (BinVal>>1) & 0x01;
MuxVal3 = (BinVal>>2) & 0x01;
digitalWrite(MuxPin1, MuxVal1);
digitalWrite(MuxPin2, MuxVal2);
digitalWrite(MuxPin3, MuxVal3);
PotValues[N]=analogRead(AnaInPin1) / 4 ;
PotValues[N + 8]=analogRead(AnaInPin2) / 4;
}
}
void sendPotValues()
{
for (N=0; N<=14; N++)
{
Serial.print(PotValues[N]);
Serial.print(',');
}
Serial.println(PotValues[15]);
}