My project involves using a 8-bit multiplexer to take in analog sensor data from 8 thermistors. I'm using a Due with a touchscreen, so I can only use 5 analog inputs. I'm trying to have a for loop to set the select pins on the multiplexor, and at each bit (000,001,010, etc.) collecting the analog input. The problem I'm having is that the digitalWrite() function is not setting the select pins to anything other than 0 when inside an if statement. They work fine outside of it (I tested all the pins with an LED from 3.3V --> ground. This is the entire for loop I'm using:
for(int state = 0; state < 8; state++){
tft.fillScreen(ILI9341_WHITE);
tft.setCursor(0, 0);
String address = String(state, BIN); //converts state to binary
tft.println(address);
int intAddress = address.toInt(); //converts binary address into int
int z = bitRead(intAddress, 2); //third bit
tft.print(z);
int y = bitRead(intAddress, 1); //second bit
tft.print(y);
int x = bitRead(intAddress, 0); //first bit
tft.println(x);
if(x == 1){
digitalWrite[53, HIGH]; //sets pin 53 to high if first bit is high
tft.print("53 is high and ");
tft.println(x);
tft.println(digitalRead(53));
}
if(x == 0){
digitalWrite[53, LOW]; //sets pin 53 to low if first bit is low
tft.print("53 is low and ");
tft.println(x);
tft.println(digitalRead(53));
}
if(y == 1){
digitalWrite[51, HIGH]; //sets pin 51 to high if first bit is high
tft.print("51 is high and ");
tft.println(y);
tft.println(digitalRead(51));
}
if (y == 0){
digitalWrite[51, LOW]; //sets pin 51 to low if first bit is low
tft.print("51 is low and ");
tft.println(y);
tft.println(digitalRead(51));
}
if(z == 1){
digitalWrite[49, HIGH]; //sets pin 49 to high if first bit is high
tft.print("49 is high and ");
tft.println(z);
tft.println(digitalRead(49));
}
if (z == 0){
digitalWrite[49, LOW]; //sets pin 49 to low if first bit is low
tft.print("49 is low and ");
tft.println(z);
tft.println(digitalRead(49));
}
realVNode[j] = analogRead(11); //adds thermistor value to int table
tft.print("analogRead: ");
tft.println(analogRead(11));
tft.print("realVNode[j]: ");
tft.println(realVNode[j]);
}
This is the data sheet of the multiplexer I'm using:
a lot of the println is just my way of debugging to see where the code gets and what it think's it's doing. From what I can tell, everything is working as it is supposed to, and digitalRead() reads all the pins (49, 51, 53) as LOW.
All the pins are set to pinMode(x, OUTPUT);
Thanks.