//Mux control pins
int s0 = 8; //Modulo pino s0 - CI.4067 pino 10 A
int s1 = 9; //Modulo pino s1 - CI.4067 pino 11 B
int s2 = 10; //Modulo pino s2 - CI.4067 pino 14 C
int s3 = 11; //Modulo pino s3 - CI.4067 pino 13 D
//Mux in "SIG" pin
int SIG_pin = 0;
//Mux inputs
#define NUM_INPUTS 3
unsigned long currentMillis = millis();
void setup(){
pinMode(s0, OUTPUT);
pinMode(s1, OUTPUT);
pinMode(s2, OUTPUT);
pinMode(s3, OUTPUT);
digitalWrite(s0, LOW);
digitalWrite(s1, LOW);
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
Serial.begin(115200);
}
void loop(){
MuxValue();
}
int readMux(int channel){
int controlPin[] = {s0, s1, s2, s3};
int muxChannel[NUM_INPUTS][4]={
{0,0,0,0}, //channel 0
{1,0,0,0}, //channel 1
{0,1,0,0}, //channel 2
};
//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
int val = analogRead(A0);
//return the value
return val;
}
int MuxValue(){
for(int i = 0; i < NUM_INPUTS; i ++){
Serial.print("Value at channel ");
Serial.print(i);
Serial.print("is : ");
Serial.println(readMux(i));
delay(500);
}
}