//Mux control pins
const int s0 = 2;
const int s1 = 4;
const int s2 = 5;
const int s3 = 18;
//Mux in "SIG" pin
const int SIG_pin = 19;
byte controlPin[] = { s0, s1, s2, s3 };
byte readMux(byte channel) {
// Loop a través de los 4 selectores
for (byte b = 0; b < 4; b++, channel >>= 1) {
digitalWrite(controlPin[b], channel & 1);
}
// Leo y devuelvo el valor
return digitalRead(SIG_pin);
}
void setup(){
pinMode(s0, OUTPUT);
pinMode(s1, OUTPUT);
pinMode(s2, OUTPUT);
pinMode(s3, OUTPUT);
pinMode(SIG_pin, INPUT_PULLUP);
digitalWrite(s0, LOW);
digitalWrite(s1, LOW);
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
Serial.begin(9600);
}
void loop(){
byte tmp = 0;
//Loop through and read all 16 values
//Reports back Value at channel 6 is: 346
for(int i = 0; i < 16; i ++){
tmp = readMux(i);
if (tmp == 0) {
Serial.printf("Canal %2d: %x\n", i, tmp);
}
delay(100);
}
}