Skip to content

Library not working properly when fast and multiple triggers are sent. #8

@GeorgeFlorian

Description

@GeorgeFlorian

Board: ESP32-EVB
GPIO: 15
DEBOUNCE_TIME: 50

The GPIO can be used as INPUT_PULLUP as I have used it before.

I am trying to implement this library in one of my projects and I am testing a PIN by putting it to LOW repeatedly and as fast as I can using my hand and a wire from GPIO 15 to GND.

This is the sketch that I've used:

#include <ezButton.h>

#define DEBOUNCE_TIME 50 // the debounce time in millisecond, increase this time if it still chatters
#define INPUT_1 15

ezButton button(INPUT_1);

void setup()
{
  Serial.begin(115200);
  button.setDebounceTime(DEBOUNCE_TIME); // set debounce time to 50 milliseconds
}

unsigned int foo = 0;

void loop()
{
  delay(1);
  button.loop(); // MUST call the loop() function first

  if (button.isPressed()){
    Serial.print("The button is pressed: ");
    Serial.println(++foo);
  }

  if (button.isReleased())
    Serial.println("The button is released");
}

I've added delay(1) inside void loop() to replicate one of my bigger projects, in which I need to place a delay inside the loop, otherwise the WDT gets triggered.

The problem is that it can register tens of presses or releases at once.

The button is pressed: 17
The button is released
The button is pressed: 18
The button is pressed: 19
The button is pressed: 20
The button is pressed: 21
The button is pressed: 22
The button is pressed: 23
The button is pressed: 24
The button is pressed: 25
The button is pressed: 26
The button is pressed: 27
The button is pressed: 28
The button is pressed: 29
The button is pressed: 30
The button is pressed: 31
The button is pressed: 32
The button is pressed: 33
The button is pressed: 34
The button is pressed: 35
The button is pressed: 36
The button is pressed: 37
The button is pressed: 38
The button is pressed: 39
The button is pressed: 40
The button is pressed: 41
The button is pressed: 42
The button is pressed: 43
The button is pressed: 44
The button is pressed: 45
The button is pressed: 46
The button is pressed: 47
The button is pressed: 48
The button is pressed: 49
The button is pressed: 50
The button is pressed: 51
The button is released
The button is pressed: 52
The button is released
...
The button is pressed: 138
The button is released
The button is released
The button is released
The button is released
The button is released
The button is released
The button is released
The button is released
The button is released
The button is released
The button is released
The button is released
The button is released
The button is released
The button is released
The button is released
The button is released
The button is released
The button is released
The button is released
The button is released
The button is released
The button is released
The button is released
The button is released
The button is released
The button is released
The button is released
The button is released
The button is released
The button is pressed: 139
The button is released

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions