How often does a button swing

I'm working on a program with an external interrupt. Thefore i have a button. But how often does the button swing (getting high and low), when pressed and released once?

erikv4:
I'm working on a program with an external interrupt. Thefore i have a button. But how often does the button swing (getting high and low), when pressed and released once?

Impossible to say and it won't be consistent. Google switch bounce.

Thanks 4 the advice.
"When the switch is closed, the two contacts actually separate and reconnect, typically 10 to 100 times over a periode of about 1ms."
Thats pretty much, what i get :slight_smile:

erikv4:
I'm working on a program with an external interrupt. Thefore i have a button. But how often does the button swing (getting high and low), when pressed and released once?

I did some testing for this recently as similar questions come up often. I used an cheap button and oscilloscope, and got close to 20ms of bounce. As to how many bounces, no idea, a lot.

Please don't use interrupts for button presses, they are the wrong tool for that job.

The buttom is just 4 simulating a Schmitt Trigger circout, which unfortunatley doesnt't work the way it should.
But Thanks for your help

erikv4:
The buttom is just 4 simulating a Schmitt Trigger circout, which unfortunatley doesnt't work the way it should.
But Thanks for your help

How should it work?

The standard hardware de-bounce circuit uses an RC low-pass filter to smear-out the bounces then a schmitt-trigger input to generate a clean logic signal edge from the analog voltage. Time constant of 10ms or thereabouts is typical. So 100k / 100nF RC filter into one section of a 74HC14 is a reasonable approach, and
the '14 can handle 6 switch inputs as its a hex inverter.

A workaround to handle multiple bounces can be added in the interrupt function:

volatile interruptFunctionCalled = false;

void myInterruptFunction()
{
  static unsigned long    triggedAt = 0;

  if (100 < millis() - triggedAt) {
    // add code to do whatever you like.
    // ... such as setting a flag that this function has been called
    interruptFunctionCalled = true;

    triggedAt = millis();
  }
}