Debounce multiple I/O

Looking to implement this debounce code for a sketch that has multiple digital inputs, and multiple digital outputs. What is the best way to implement this, as this example is for one input and one output? Does anyone know of a sample code or something from the playground where this debounce has been implemented for multiple inputs? If you know, could you please share. Thanks so much.

Looking to implement this debounce code

What debounce code?

What is the best way to implement this

Only on the inputs that might bounce. If it hasn't changed, it isn't bouncing.

If you detect an input has change then don't look at that input again for 20mS.

Most of the time you don't need to specifically do anything to achieve this, the rest of the code acts as a delay. I very rarely have to take debounce precautions.

Perhaps it's easier to share some code:

In a nutshell, switch closed, it runs two outputs until the switch opens again. There are delays for 1 of the outputs for both turning them on and off.

I would like to debounce S1 and the other switches because it will be a very gradual contact closure and I'm concerned about bouncing. What's the best way to do a double read with a delay between reads on this setup? And should I include it in every switch check/run or just at the beginning and define some variables? Many thanks.

void loop() {
// Begin Water Tank 1 Logic
  if (digitalRead(S1) == LOW && curS == 0) 
    Serial.println("Filling Tank 1");
    digitalWrite(K1, HIGH);
    digitalWrite(K4, HIGH);
    curS = S1;  
  else if (digitalRead(S1) == HIGH && curS == S1) 
    Serial.println("Tank 1 Full");
    digitalWrite(K4, LOW);
    digitalWrite(K1, LOW);
    curS = 0;

because it will be a very gradual contact closure

No such thing, a contact is either closed or it is not. Can you be more specific?

Have you seen effects of contact bounce or is this just what you think you need to do?

You have a


in the code between detecting a contact closure and looking for the next. That's 3 seconds of debounce time already built into the thing, you need more?


Thanks for your response. Perhaps a better wording. It's a water level tank sensor, basically a microswitch electrically. I've seen it bounce but only with human interaction, actually closing the switch myself when I initially tested it with a breadboard on the arduino to get the logic I needed. I really have on idea if it will bounce in it's actual application. I would just like to de-bounce it or know how to when I get the system installed should it bounce. I guess maybe you've answered my question; I just wasn't sure if that delay I have in there for another reason is a sufficient way in itself to debounce it? I'm just trying to be thorough is all. Thanks Mike.

Normally a debounce delay would be 20mS, you have a delay of 3000mS, so another 20 is going to make no difference.