4067 Multiplexer code question

OK, we been here before.

I'm off to you know where, but I think if you spent some time on the ideas I sketched <-- see what I did there? in post #64 above, it might be enough to get started.

A way to add indivdirectly read analog inputs and treat them as if the were extra channels on the multiplexer.

Which raises the question: why not just use more mux inputs? If the mix you using only has 4 channels, it seems like it would be easier fix to get a wider multiplexer.

Dunno where you old problems were, but keep a watch for stray or mismatched or missing { braces }, and always use Auto Format and give your code a good look to be sure it is structured the way you want.

L8R

a7

edit:

Can I print the analog values from the A0 in same row to be looked like this:

So if I will have more inputs on the mux they will be added to the right with a space.

I need help adding the option to read other analog inputs apart from the multiplexer.

I try to go over a7 example at post #64 but I got stuck.

I don't understand how to make the code checking the other analog inputs after go over all the multiplexer inputs.
I started to edit the code and this is where I have got:

#define ENABLED                        true
#define DISABLED                       false

#define N_MUX_INPUTS                     3
# define N_OTHER_INPUTS                  1
# define N_INPUTS  (N_MUX_INPUTS + N_OTHER_INPUTS)


//                                     s0 s1  s2  s3
const byte addressPin[]              = {8, 9, 10, 11};

const byte muxChannel[N_MUX_INPUTS][4] =
{
  {0, 0, 0, 0}, //channel 0
  {1, 0, 0, 0}, //channel 1
  {0, 1, 0, 0}, //channel 2
//{1, 1, 0, 0}, //channel 3
//{0, 0, 1, 0}, //channel 4
//{1, 0, 1, 0}, //channel 5
//{0, 1, 1, 0}, //channel 6
//{1, 1, 1, 0}, //channel 7
//{0, 0, 0, 1}, //channel 8
//{1, 0, 0, 1}, //channel 9
//{0, 1, 0, 1}, //cahennl 10
//{1, 1, 0, 1}, //channel 11
//{0, 0, 1, 1}, //channel 12
//{1, 0, 1, 1}, //channel 13
//{0, 1, 1, 1}, //channel 14
//{1, 1, 1, 1}  //channel 15
};

// verify non blocking code//
const byte heartbeatLED       = 13;

//Mux in "SIG" pin
const byte  SIG_pin           = A0;

//Others analog pin inputs
const byte otherSIG_pin[N_OTHER_INPUTS] = {A1};

int sigValue;


boolean sampleFlag            = DISABLED;

byte muxAddress;
byte filter               = 1; //whatever is needed

int muxValue;
int lastValue[N_INPUTS];

bool isOn[N_INPUTS];
bool isOnPre[N_INPUTS];

////mapping values      ch0  ch1 ch2  ch3 ch4
//const int lowEnd[] = {0, 0, 500, 0, 0};
//const int highEnd[] = {1023, 1023, -50, 1000, 1023};

//timing stuff//
unsigned long heartbeatMillis;
unsigned long readMuxMillis;
unsigned long settlingMillis;
unsigned long readSigMillis;

//********************************************^************************************************
void setup()
{
  Serial.begin(115200);

  pinMode(heartbeatLED, OUTPUT);

  for (byte x = 0; x <= 3; x++)
  {
    pinMode(addressPin[x], OUTPUT);
    digitalWrite(addressPin[x], LOW);
  }

} 

void loop()
{
  checkHeartbeatTIMER();

  checkReadMuxTIMER();

  checkSettlingTIMER();


} 


//// functions ////
void checkHeartbeatTIMER()
{
  //*********************************                                heartbeat TIMER
  //is it time to toggle the heartbeatLED ?
  if (millis() - heartbeatMillis >= 500ul)
  {
    //restart this TIMER
    heartbeatMillis = millis();

    //toggle the heartbeatLED
    digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
  }

} //END of   checkHeartbeatTIMER()




void checkReadMuxTIMER()
{
  //*********************************                                readMux TIMER
  //is it time to read the next mux analog ?
  if (millis() - readMuxMillis >= 5ul)
  {
    //restart this TIMER
    readMuxMillis = millis();

    //send the new address to the CD4067 mux
    for (byte i = 0; i < 4; i ++)
    {
      digitalWrite(addressPin[i], muxChannel[muxAddress][i]);
    }

    //enable the analog settling TIMER
    sampleFlag = ENABLED;

    //restart the analog settling TIMER
    settlingMillis = millis();
  }

} //END of   checkReadMuxTIMER()



void checkSettlingTIMER()
{
  //*********************************                                settling TIMER
  //if this TIMER is enabled, has this it expired ?
  if (sampleFlag == ENABLED && millis() - settlingMillis >= 5ul)
  {
    //we are now finished with this analog settling TIMER
    sampleFlag = DISABLED;

    //read the stabilized analog
    muxValue = analogRead(SIG_pin);

    //has analog value changed more than the filter amount ?
    if (abs(lastValue[muxAddress] - muxValue) > filter)
    {
      //update to the new value
      lastValue[muxAddress] = muxValue;
//      /* new feature removed for now
      if (lastValue[muxAddress] >= 2)     // should mux channel be on?
      {
        if (isOn[muxAddress] == 0)    // was it off? tell us it went on
        {
          isOn[muxAddress] = 1;       // remember it went on
          Serial.print("ch");
          Serial.print(muxAddress);
          Serial.print("on "); // and say so
          Serial.println(isOn[muxAddress]);
        }
      }
      else                               // mux channel should be off
      {
        if (isOn[muxAddress] == 1)    // was it on? tell us it went off
        {
          isOn[muxAddress] = 0;       // remember it is off
          Serial.print("ch");
          Serial.print(muxAddress);
          Serial.print("on "); // and say so
          Serial.println(isOn[muxAddress]);
        }
      }
//new feature removed for now */

      //log the new value of the selected analog
//      muxValue = map(muxValue, 0, 1023, lowEnd[muxAddress], highEnd[muxAddress]);

       Serial.print("value_ch");
       Serial.print(muxAddress);
       Serial.print(" ");
       Serial.println(muxValue);
    }

    //prepare for the new/next mux address
    muxAddress++;

    //have we read all the inputs ?
    if (muxAddress > N_MUX_INPUTS - 1)
    {
      //back to the first address
      muxAddress = 0;
    }
  }

} //END of   checkSettlingTIMER()


//********************************************^************************************************

All I can do right now is to ask you to carefully read #64.

If you have specific questions about it, pose them here.

Your attempt does not seem to have any of the essential changes that #64 outlines.

In particular, see if you can appreciate the combination of the ancillary data require for each channel, no matter mux or direct, that is achieved by the single larger arrays.

I may have more time later, but short of just telling you to move away from the keyboard and typing it myself, I can offer no help without specific questions demonstrating you are coming to an understanding of #64.

a7

The function for checking the mux inputs should stay as it is:

void checkReadMuxTIMER()
{
  //*********************************                                readMux TIMER
  //is it time to read the next mux analog ?
  if (millis() - readMuxMillis >= 5ul)
  {
    //restart this TIMER
    readMuxMillis = millis();

    //send the new address to the CD4067 mux
    for (byte i = 0; i < 4; i ++)
    {
      digitalWrite(addressPin[i], muxChannel[muxAddress][i]);
    }

    //enable the analog settling TIMER
    sampleFlag = ENABLED;

    //restart the analog settling TIMER
    settlingMillis = millis();
  }

} //END of   checkReadMuxTIMER()

here is the function I'm assuming I should make the changes and read the other inputs as well as the mux inputs

void checkSettlingTIMER()
{
  //*********************************                                settling TIMER
  //if this TIMER is enabled, has this it expired ?
  
  if (sampleFlag == ENABLED && millis() - settlingMillis >= 5ul)
  {
    //we are now finished with this analog settling TIMER
    sampleFlag = DISABLED;

    //read the stabilized analog
    muxValue = analogRead(SIG_pin);

    //has analog value changed more than the filter amount ?
    if (abs(lastValue[muxAddress] - muxValue) > filter)
    {
      //update to the new value
      lastValue[muxAddress] = muxValue;
//      /* new feature removed for now
      if (lastValue[muxAddress] >= 2)     // should mux channel be on?
      {
        if (isOn[muxAddress] == 0)    // was it off? tell us it went on
        {
          isOn[muxAddress] = 1;       // remember it went on
          Serial.print("ch");
          Serial.print(muxAddress);
          Serial.print("on "); // and say so
          Serial.println(isOn[muxAddress]);
        }
      }
      else                               // mux channel should be off
      {
        if (isOn[muxAddress] == 1)    // was it on? tell us it went off
        {
          isOn[muxAddress] = 0;       // remember it is off
          Serial.print("ch");
          Serial.print(muxAddress);
          Serial.print("on "); // and say so
          Serial.println(isOn[muxAddress]);
        }
      }
//new feature removed for now */

      //log the new value of the selected analog
//      muxValue = map(muxValue, 0, 1023, lowEnd[muxAddress], highEnd[muxAddress]);

       Serial.print("value_ch");
       Serial.print(muxAddress);
       Serial.print(" ");
       Serial.println(muxValue);
    }

    //prepare for the new/next mux address
    muxAddress++;

    //have we read all the inputs ?
    if (muxAddress > N_MUX_INPUTS - 1)
    {
      //back to the first address
      muxAddress = 0;
    }
  }

} //END of   checkSettlingTIMER()

I Don't understand how can I make the other analog inputs to be as an extended to the mux inputs?
Do I need in some way to make the code that read through all the mux inputs to read from the other analog inputs before he is back to read from mux input 1?

maybe I should make a change in the section:

 //have we read all the inputs ?
    if (muxAddress > N_MUX_INPUTS - 1)
    {
      //back to the first address
      muxAddress = 0;
    }

instead of back to read first address, now iterate over all other analog pins?

First: you have consistently ignored my repeated question about the roll of the "settling" time. It is an unusual mechanism and makes the logic complicate. What is settling? What is the significance of the 5 ms settling time?

In post #80 you implied that you had a fully working sketch that used the multiplexer and the additional direct analog inputs.

To which sketch you wanted to add a new feature. That channel on/off logic we worked out thoroughly.

Please post that #80 sketch that works for all inputs, but does not yet have the new feature.

I cannot deal with little glimpses into how you are trying valiantly to add you new feature.

If you have no such sketch, sorry, I inferred something incorrect.

Post then the best last sketch that work, you are happy with, I think it had the mapping and filtering and stuff. Not gonna go through the whole thread trying to collect your successes and failures.

Adding features to sketches that do not work is, as I must repeat myself by saying, insane.

It does not appear that you are looking at or trying to figure out my #64, but you do seem to have grasped the idea that iterating will indeed become an idea that goes over all the inputs, mix and direct.

a7

Yes, to that one.

Here is the sketch that works for all mux inputs including 0 and 1 for reporting if a sensor is pressed or not.
This sketch is not including the new feature of extra analog inputs.

#define ENABLED                        true
#define DISABLED                       false

#define NUM_INPUTS                     3

//                                     s0 s1  s2  s3
const byte addressPin[]              = {8, 9, 10, 11};

const byte muxChannel[NUM_INPUTS][4] =
{
  {0, 0, 0, 0}, //channel 0
  {1, 0, 0, 0}, //channel 1
  {0, 1, 0, 0}, //channel 2
//{1, 1, 0, 0}, //channel 3
//{0, 0, 1, 0}, //channel 4
//{1, 0, 1, 0}, //channel 5
//{0, 1, 1, 0}, //channel 6
//{1, 1, 1, 0}, //channel 7
//{0, 0, 0, 1}, //channel 8
//{1, 0, 0, 1}, //channel 9
//{0, 1, 0, 1}, //cahennl 10
//{1, 1, 0, 1}, //channel 11
//{0, 0, 1, 1}, //channel 12
//{1, 0, 1, 1}, //channel 13
//{0, 1, 1, 1}, //channel 14
//{1, 1, 1, 1}  //channel 15
};

// verify non blocking code//
const byte heartbeatLED       = 13;

//Mux in "SIG" pin
const byte  SIG_pin           = A0;


int sigValue;


boolean sampleFlag            = DISABLED;

byte muxAddress;
byte filter               = 1; //whatever is needed

int muxValue;
int lastValue[NUM_INPUTS];

bool muxIsOn[NUM_INPUTS];
bool muxIsOnPre[NUM_INPUTS];

////mapping values      ch0  ch1 ch2  ch3 ch4
//const int lowEnd[] = {0, 0, 500, 0, 0};
//const int highEnd[] = {1023, 1023, -50, 1000, 1023};

//timing stuff//
unsigned long heartbeatMillis;
unsigned long readMuxMillis;
unsigned long settlingMillis;
unsigned long readSigMillis;

//********************************************^************************************************
void setup()
{
  Serial.begin(115200);

  pinMode(heartbeatLED, OUTPUT);

  for (byte x = 0; x <= 3; x++)
  {
    pinMode(addressPin[x], OUTPUT);
    digitalWrite(addressPin[x], LOW);
  }

} 

void loop()
{
  checkHeartbeatTIMER();

  checkReadMuxTIMER();

  checkSettlingTIMER();


 

} 


//// functions ////
void checkHeartbeatTIMER()
{
  //*********************************                                heartbeat TIMER
  //is it time to toggle the heartbeatLED ?
  if (millis() - heartbeatMillis >= 500ul)
  {
    //restart this TIMER
    heartbeatMillis = millis();

    //toggle the heartbeatLED
    digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
  }

} //END of   checkHeartbeatTIMER()




void checkReadMuxTIMER()
{
  //*********************************                                readMux TIMER
  //is it time to read the next mux analog ?
  if (millis() - readMuxMillis >= 5ul)
  {
    //restart this TIMER
    readMuxMillis = millis();

    //send the new address to the CD4067 mux
    for (byte i = 0; i < 4; i ++)
    {
      digitalWrite(addressPin[i], muxChannel[muxAddress][i]);
    }

    //enable the analog settling TIMER
    sampleFlag = ENABLED;

    //restart the analog settling TIMER
    settlingMillis = millis();
  }

} //END of   checkReadMuxTIMER()



void checkSettlingTIMER()
{
  //*********************************                                settling TIMER
  //if this TIMER is enabled, has this it expired ?
  if (sampleFlag == ENABLED && millis() - settlingMillis >= 5ul)
  {
    //we are now finished with this analog settling TIMER
    sampleFlag = DISABLED;

    //read the stabilized analog
    muxValue = analogRead(SIG_pin);

    //has analog value changed more than the filter amount ?
    if (abs(lastValue[muxAddress] - muxValue) > filter)
    {
      //update to the new value
      lastValue[muxAddress] = muxValue;
//      /* new feature removed for now
      if (lastValue[muxAddress] >= 2)     // should mux channel be on?
      {
        if (muxIsOn[muxAddress] == 0)    // was it off? tell us it went on
        {
          muxIsOn[muxAddress] = 1;       // remember it went on
          Serial.print("ch");
          Serial.print(muxAddress);
          Serial.print("on "); // and say so
          Serial.println(muxIsOn[muxAddress]);
        }
      }
      else                               // mux channel should be off
      {
        if (muxIsOn[muxAddress] == 1)    // was it on? tell us it went off
        {
          muxIsOn[muxAddress] = 0;       // remember it is off
          Serial.print("ch");
          Serial.print(muxAddress);
          Serial.print("on "); // and say so
          Serial.println(muxIsOn[muxAddress]);
        }
      }
//new feature removed for now */

      //log the new value of the selected analog
//      muxValue = map(muxValue, 0, 1023, lowEnd[muxAddress], highEnd[muxAddress]);

       Serial.print("value_ch");
       Serial.print(muxAddress);
       Serial.print(" ");
       Serial.println(muxValue);
    }

    //prepare for the new/next mux address
    muxAddress++;

    //have we read all the inputs ?
    if (muxAddress > NUM_INPUTS - 1)
    {
      //back to the first address
      muxAddress = 0;
    }
  }

} //END of   checkSettlingTIMER()


//********************************************^************************************************

I try to look into it and understand were I should and how to add the new feature with no success

Again, last time:

What is the roll of the "settling" time. It is an unusual mechanism and makes the logic complicate. What is settling? What is the significance of the 5 ms settling time?

a7

It is explained by LarryD at post #36
from what I understand is to give the mux a time to received the address voltages at pin 8,9,10 and 11.

But look at what he said:

us. Microseconds. A few.

It is sufficient and better and OK to just

   delayMicroseconds(5);

at the right place in you code. Five microseconds is a virtual eternity in the realm of digital logic "settling", so I suggest you lose the entire notion of a settling period lasting 1000 times longer (!) and just put a tiny little delay in there after you set the max address pins.

This will very simplify your code, asking it easier to see why it is doing what it does, and not doing what it should as you tinker with it.

a7

where should I placed that delayMicroseconds(5); ?

can't I just change this line:
(edit: the answer is NO)

  if (millis() - readMuxMillis >= 5ul)

to:

  if (millis() - readMuxMillis >= 0.005ul)

?

here is my take that seems to work:

void checkReadMuxTIMER()
{
  //*********************************                                readMux TIMER

    //send the new address to the CD4067 mux
    for (byte i = 0; i < 4; i ++)
    {
      digitalWrite(addressPin[i], muxChannel[muxAddress][i]);
    }

    //enable the analog settling TIMER
    sampleFlag = ENABLED;

// delay for next reading
    delayMicroseconds(5);
  }

 //END of   checkReadMuxTIMER()

any input about the above?

Yes. The comment might better read

// allow mix address pins to settle

and obvsly the entire settling function can be removed.

Your first idea was a good stab, except… all those millis are integers, and won't compare the way you think to a number like 0.005.

So post the latest best once it works. You could look to see why you didn't ever finish with the extra direct inputs, all that work gone somehow?

Perhaps for the best, because #64 will be a better approach anyway.

Also can't look closely now, but where is the map and filter logic? I thought it was missing from the latest, so is that progress lost also?

Again, perhaps for the best. But you have to start keeping track of what is where or you be re-I venting the wheel or asking us to,solve problems what have already been. Solved.

Step by step.

a7

I've removed completely the mapping option as I will do the mapping to certain values at another program.

filtering is still there.

Here is the latest working code:

#define ENABLED                        true
#define DISABLED                       false

#define NUM_INPUTS                     3

//                                     s0 s1  s2  s3
const byte addressPin[]              = {8, 9, 10, 11};

const byte muxChannel[NUM_INPUTS][4] =
{
  {0, 0, 0, 0}, //channel 0
  {1, 0, 0, 0}, //channel 1
  {0, 1, 0, 0}, //channel 2
//{1, 1, 0, 0}, //channel 3
//{0, 0, 1, 0}, //channel 4
//{1, 0, 1, 0}, //channel 5
//{0, 1, 1, 0}, //channel 6
//{1, 1, 1, 0}, //channel 7
//{0, 0, 0, 1}, //channel 8
//{1, 0, 0, 1}, //channel 9
//{0, 1, 0, 1}, //cahennl 10
//{1, 1, 0, 1}, //channel 11
//{0, 0, 1, 1}, //channel 12
//{1, 0, 1, 1}, //channel 13
//{0, 1, 1, 1}, //channel 14
//{1, 1, 1, 1}  //channel 15
};

// verify non blocking code//
const byte heartbeatLED       = 13;

//Mux in "SIG" pin
const byte  SIG_pin           = A0;


int sigValue;


boolean sampleFlag            = DISABLED;

byte muxAddress;
byte filter               = 5; //whatever is needed

int muxValue;
int lastValue[NUM_INPUTS];

bool muxIsOn[NUM_INPUTS];
bool muxIsOnPre[NUM_INPUTS];

//timing stuff//
unsigned long heartbeatMillis;
unsigned long readMuxMillis;
unsigned long readSigMillis;

//********************************************^************************************************
void setup()
{
  Serial.begin(115200);

  pinMode(heartbeatLED, OUTPUT);

  for (byte x = 0; x <= 3; x++)
  {
    pinMode(addressPin[x], OUTPUT);
    digitalWrite(addressPin[x], LOW);
  }

} 

void loop()
{
  checkHeartbeatTIMER();

  checkReadMuxTIMER();

  checkSettlingTIMER();


} 


//// functions ////
void checkHeartbeatTIMER()
{
  //*********************************                                heartbeat TIMER
  //is it time to toggle the heartbeatLED ?
  if (millis() - heartbeatMillis >= 500ul)
  {
    //restart this TIMER
    heartbeatMillis = millis();

    //toggle the heartbeatLED
    digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
  }

} //END of   checkHeartbeatTIMER()




void checkReadMuxTIMER()
{
  //*********************************                                readMux TIMER

    //send the new address to the CD4067 mux
    for (byte i = 0; i < 4; i ++)
    {
      digitalWrite(addressPin[i], muxChannel[muxAddress][i]);
    }

    //enable the analog settling TIMER
    sampleFlag = ENABLED;

    // allow mix address pins to settle
    delayMicroseconds(5);
  }

 //END of   checkReadMuxTIMER()



void checkSettlingTIMER()
{
  //*********************************                                settling TIMER
  //if this TIMER is enabled, has this it expired ?
  if (sampleFlag == ENABLED )
  {
    //we are now finished with this analog settling TIMER
    sampleFlag = DISABLED;

    //read the stabilized analog
    muxValue = analogRead(SIG_pin);

    //has analog value changed more than the filter amount ?
    if (abs(lastValue[muxAddress] - muxValue) > filter)
    {
      //update to the new value
      lastValue[muxAddress] = muxValue;

      //is sensor is pressed ?? // print 0 or 1 //
      
      if (lastValue[muxAddress] >= 2)     // should mux channel be on?
      {
        if (muxIsOn[muxAddress] == 0)    // was it off? tell us it went on
        {
          muxIsOn[muxAddress] = 1;       // remember it went on
          Serial.print("ch");
          Serial.print(muxAddress);
          Serial.print("on "); // and say so
          Serial.println(muxIsOn[muxAddress]);
        }
      }
      else                               // mux channel should be off
      {
        if (muxIsOn[muxAddress] == 1)    // was it on? tell us it went off
        {
          muxIsOn[muxAddress] = 0;       // remember it is off
          Serial.print("ch");
          Serial.print(muxAddress);
          Serial.print("on "); // and say so
          Serial.println(muxIsOn[muxAddress]);
        }
      }

       Serial.print("value_ch");
       Serial.print(muxAddress);
       Serial.print(" ");
       Serial.println(muxValue);
    }

    //prepare for the new/next mux address
    muxAddress++;

    //have we read all the inputs ?
    if (muxAddress > NUM_INPUTS - 1)
    {
      //back to the first address
      muxAddress = 0;
    }
  }

} //END of   checkSettlingTIMER()


//********************************************^************************************************

Your function names are kinda misleading now, I suggest you change them to reflect what they actually do.

The sampleFlag variable serves no purpose other than to add lines of code that do nothing logically.

The process runs flat out as you removed the idiomatic millis() mechanism which held sampling to no more than 200 per second, or once every 20 ms for a given channel. Did you ma]ean to do that?

Lastly, what is the problem with or objection to doing the extra channels by routing them through the multiplexer as is done with the four now working?

I am flattered that you took my comment with a cut and paste, but you might have fixed my typo whilst doing, I meant "mux" not "mix". :wink:

a7

What do you mean by runs flat out?

Flat out is expression meaning doing something as quickly as you can: e.g. "I worked flat out to finish the assignment."

In this context, running flat out means the times between subsequent full executions of the processes in your loop() function is determined only by how long the operations take, not by any timing mechanism such as the one in the heart beat function, or the several that were once part of the other two functions.

This is not necessarily a bad thing, just a difference to how your code worked before.

Many sketches run flat out just fine. For some sketches, doing something every 20 ms is important, even if 18 of those are wasted waiting for a millis() style mechanism to figure out that it is time to execute again - like a frame of an animation, for example.

If the step in the process itself takes 3 or 7 or 11 ms it matters not - it will only repeat every 20 ms.

So it is a matter to consider, not be unaware of.

a7

ok I understand that.

I can't make it work! reading all mux and other sig inputs

I try to add another function that read the other analog inputs with no success.

#define ENABLED                        true
#define DISABLED                       false

#define  N_MUX_INPUTS                    3
#define N_OTHER_INPUTS                   3
#define N_INPUTS  (N_MUX_INPUTS + N_OTHER_INPUTS)

//                                     s0 s1  s2  s3
const byte addressPin[]              = {8, 9, 10, 11};

const byte muxChannel[ N_MUX_INPUTS][4] =
{
  {0, 0, 0, 0}, //channel 0
  {1, 0, 0, 0}, //channel 1
  {0, 1, 0, 0}, //channel 2
//{1, 1, 0, 0}, //channel 3
//{0, 0, 1, 0}, //channel 4
//{1, 0, 1, 0}, //channel 5
//{0, 1, 1, 0}, //channel 6
//{1, 1, 1, 0}, //channel 7
//{0, 0, 0, 1}, //channel 8
//{1, 0, 0, 1}, //channel 9
//{0, 1, 0, 1}, //cahennl 10
//{1, 1, 0, 1}, //channel 11
//{0, 0, 1, 1}, //channel 12
//{1, 0, 1, 1}, //channel 13
//{0, 1, 1, 1}, //channel 14
//{1, 1, 1, 1}  //channel 15
};

const byte otherSIG_pin[N_OTHER_INPUTS] = {A1, A2, A3};

// verify non blocking code//
const byte heartbeatLED       = 13;

//Mux in "SIG" pin
const byte  SIG_pin           = A0;


int sigValue;

// all  previous values
int lastValue[N_INPUTS];

int muxValue;





byte muxAddress;
byte filter               = 5; //whatever is needed



bool muxIsOn[ N_MUX_INPUTS];
bool muxIsOnPre[ N_MUX_INPUTS];

//timing stuff//
unsigned long heartbeatMillis;
unsigned long readMuxMillis;
unsigned long readSigMillis;
unsigned long settlingMillis;

//********************************************^************************************************
void setup()
{
  Serial.begin(115200);

  pinMode(heartbeatLED, OUTPUT);

  for (byte x = 0; x <= 3; x++)
  {
    pinMode(addressPin[x], OUTPUT);
    digitalWrite(addressPin[x], LOW);
  }

} 

void loop()
{
  checkHeartbeatTIMER();

  checkReadMuxTIMER();

  readingMultiplexer();

readingOtherInputs ();


} 


//// functions ////
void checkHeartbeatTIMER()
{
  //*********************************                                heartbeat TIMER
  //is it time to toggle the heartbeatLED ?
  if (millis() - heartbeatMillis >= 500ul)
  {
    //restart this TIMER
    heartbeatMillis = millis();

    //toggle the heartbeatLED
    digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
  }

} //END of   checkHeartbeatTIMER()




void checkReadMuxTIMER()
{
  //*********************************                                readMux TIMER

    //send the new address to the CD4067 mux
    for (byte i = 0; i < 4; i ++)
    {
      digitalWrite(addressPin[i], muxChannel[muxAddress][i]);
    }
    // allow mix address pins to settle
    settlingMillis = millis();
    delayMicroseconds(5);
  }

 //END of   checkReadMuxTIMER()



void readingMultiplexer()
{
  //*********************************                                settling TIMER
if( millis() - settlingMillis >= 20ul)
{
    //read the stabilized analog
    muxValue = analogRead(SIG_pin);

    //has analog value changed more than the filter amount ?
    if (abs(lastValue[muxAddress] - muxValue) > filter)
    {
      //update to the new value
      lastValue[muxAddress] = muxValue;

      //is sensor is pressed ?? // print 0 or 1 //
      
      if (lastValue[muxAddress] >= 2)     // should mux channel be on?
      {
        if (muxIsOn[muxAddress] == 0)    // was it off? tell us it went on
        {
          muxIsOn[muxAddress] = 1;       // remember it went on
          Serial.print("ch");
          Serial.print(muxAddress);
          Serial.print("on "); // and say so
          Serial.println(muxIsOn[muxAddress]);
        }
      }
      else                               // mux channel should be off
      {
        if (muxIsOn[muxAddress] == 1)    // was it on? tell us it went off
        {
          muxIsOn[muxAddress] = 0;       // remember it is off
          Serial.print("ch");
          Serial.print(muxAddress);
          Serial.print("on "); // and say so
          Serial.println(muxIsOn[muxAddress]);
        }
      }

       Serial.print("value_ch");
       Serial.print(muxAddress);
       Serial.print(" ");
       Serial.println(muxValue);
    }

    //prepare for the new/next mux address
    muxAddress++;

    //have we read all the inputs ?
    if (muxAddress >  N_MUX_INPUTS - 1)
    {
      //back to the first address
      muxAddress = 0;
    }
  }
}
//END of   readingMultiplexer()

void readingOtherInputs ()
  {
   if( millis() - settlingMillis >= 20ul)
   for (int i; i < otherSIG_pin; i++)
{ 
  sigValue = analogRead(otherSIG_pin[i]);
  settlingMillis = millis();
  
}
 }   



//********************************************^************************************************

Sry, under the umbrella.

At a glance:

You cannot share timing variables. Each thing, heart beat, read some things, read some other things has to have its own.

As you have heartbeatMillis just for your beating heart. Nice idea, BTW, beating hear LED.

Get the settlingTimer out of checkReadMuxTIMER() and please, please rename it, like setMuxAddress().

And there is no more concern with timing any settling, so rename that variable.

Follow the pattern in checkHeartbeatTIMER() in other things you want to do periodically.

Also, it would really help convince me you paying attention if you would kindly answer questions that I ask.

What is the problem with, our your objection to, simply using the other channels on the multiplexer?

The multiplexer will be with 16 sensors and I would like to read another 3 sensor in addition to the 16 read by the multiplexer

done.

done too.

done. changed to: readingTime


here is were I got:

#define ENABLED                        true
#define DISABLED                       false

#define  N_MUX_INPUTS                    3
#define N_OTHER_INPUTS                   3
#define N_INPUTS  (N_MUX_INPUTS + N_OTHER_INPUTS)

//                                     s0 s1  s2  s3
const byte addressPin[]              = {8, 9, 10, 11};

const byte muxChannel[ N_MUX_INPUTS][4] =
{
  {0, 0, 0, 0}, //channel 0
  {1, 0, 0, 0}, //channel 1
  {0, 1, 0, 0}, //channel 2
//{1, 1, 0, 0}, //channel 3
//{0, 0, 1, 0}, //channel 4
//{1, 0, 1, 0}, //channel 5
//{0, 1, 1, 0}, //channel 6
//{1, 1, 1, 0}, //channel 7
//{0, 0, 0, 1}, //channel 8
//{1, 0, 0, 1}, //channel 9
//{0, 1, 0, 1}, //cahennl 10
//{1, 1, 0, 1}, //channel 11
//{0, 0, 1, 1}, //channel 12
//{1, 0, 1, 1}, //channel 13
//{0, 1, 1, 1}, //channel 14
//{1, 1, 1, 1}  //channel 15
};

const byte otherSIG_pin[N_OTHER_INPUTS] = {A1, A2, A3};

// verify non blocking code//
const byte heartbeatLED       = 13;

//Mux in "SIG" pin
const byte  SIG_pin           = A0;


int sigValue;

// all  previous values
int lastValue[N_INPUTS];

int muxValue;





byte muxAddress;
byte filter               = 5; //whatever is needed



bool muxIsOn[ N_MUX_INPUTS];
bool muxIsOnPre[ N_MUX_INPUTS];

//timing stuff//
unsigned long heartbeatMillis;
unsigned long readMuxMillis;
unsigned long readSigMillis;
unsigned long readingTimeMux;
unsigned long readingTimeOtherInputs;

//********************************************^************************************************
void setup()
{
  Serial.begin(115200);

  pinMode(heartbeatLED, OUTPUT);

  for (byte x = 0; x <= 3; x++)
  {
    pinMode(addressPin[x], OUTPUT);
    digitalWrite(addressPin[x], LOW);
  }

} 

void loop()
{
  checkHeartbeatTIMER();

  setMuxAddress();

  readingMultiplexer();

readingOtherInputs ();


} 


//// functions ////
void checkHeartbeatTIMER()
{
  //*********************************                                heartbeat TIMER
  //is it time to toggle the heartbeatLED ?
  if (millis() - heartbeatMillis >= 500ul)
  {
    //restart this TIMER
    heartbeatMillis = millis();

    //toggle the heartbeatLED
    digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
  }

} //END of   checkHeartbeatTIMER()




void setMuxAddress()
{
  //*********************************                                readMux TIMER

    //send the new address to the CD4067 mux
    for (byte i = 0; i < 4; i ++)
    {
      digitalWrite(addressPin[i], muxChannel[muxAddress][i]);
    }
    delayMicroseconds(5);
  }

 //END of   setMuxAddress()



void readingMultiplexer()
{
  //*********************************                                settling TIMER
if( millis() - readingTimeMux >= 20ul)
{
    //read the stabilized analog
    muxValue = analogRead(SIG_pin);

    //has analog value changed more than the filter amount ?
    if (abs(lastValue[muxAddress] - muxValue) > filter)
    {
      //update to the new value
      lastValue[muxAddress] = muxValue;

      //is sensor is pressed ?? // print 0 or 1 //
      
      if (lastValue[muxAddress] >= 2)     // should mux channel be on?
      {
        if (muxIsOn[muxAddress] == 0)    // was it off? tell us it went on
        {
          muxIsOn[muxAddress] = 1;       // remember it went on
          Serial.print("ch");
          Serial.print(muxAddress);
          Serial.print("on "); // and say so
          Serial.println(muxIsOn[muxAddress]);
        }
      }
      else                               // mux channel should be off
      {
        if (muxIsOn[muxAddress] == 1)    // was it on? tell us it went off
        {
          muxIsOn[muxAddress] = 0;       // remember it is off
          Serial.print("ch");
          Serial.print(muxAddress);
          Serial.print("on "); // and say so
          Serial.println(muxIsOn[muxAddress]);
        }
      }

       Serial.print("value_ch");
       Serial.print(muxAddress);
       Serial.print(" ");
       Serial.println(muxValue);
    }

    //prepare for the new/next mux address
    muxAddress++;

    //have we read all the inputs ?
    if (muxAddress >  N_MUX_INPUTS - 1)
    {
      //back to the first address
      muxAddress = 0;
    }
  }
}
//END of   readingMultiplexer()

void readingOtherInputs ()
  {
   if( millis() - readingTimeMux >= 20ul)
   for (int i; i < otherSIG_pin; i++)
{ 
  sigValue = analogRead(otherSIG_pin[i]);
  readingTimeOtherInputs = millis();
  
}
 }   



//********************************************^************************************************