I'm trying to create a library , I'm trying to solve the debounce problem , when it get an input it add to the counter +1 until it reach the specific number +5 then it will say the button is pressed else , the button is not pressed and reset the counter 0 , the problem I think it's on the definition , I have tried to use with the serial monitor , to get an input to use it with a led on pin 13 ,

Your class, debounce, does not have a reset() method OR a button_state() method.

You never create an instance of the class to call methods on.

You don't seem to understand that C (and C++) is a call by value language. That is, arguments to functions may be changed by the function, but the caller will have no idea that the function may have changed its copy of the value.

Hi, // read the state of the pushbutton value: buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed. // if it is, the buttonState is HIGH: if (buttonState == LOW) { // turn LED on: digitalWrite(ledPin, HIGH); // print out the state of the button: if (switch0 == 0){ Serial.print("ON "); Serial.println(buttonState); switch0=1; ///<<--------------THIS ONE WORKS FOR ME AND NEVER MISSED HOW LONG/SHORT THE BUTTON HAS BEEN PRESSED } } else { // turn LED off: digitalWrite(ledPin, LOW); if (switch0==1){ Serial.print("OFF "); Serial.println(buttonState); switch0=0; ///<<--------------THIS ONE WORKS FOR ME AND NEVER MISSED HOW LONG/SHORT THE BUTTON HAS BEEN PRESSED }

Hi, I tried the debounce in the example and it does not work for my application, any name will do, debounce, latch, lock as long as it has met the objective, just want to share, it is for all who those who wants to try.

Hi, I tried the debounce in the example and it does not work for my application, any name will do, debounce, latch, lock as long as it has met the objective, just want to share, it is for all who those who wants to try.

Thanks,

Josh

Actually name does matter, because a latch and a debounced button/switch are two different things.

Hi, @Fire1 I would suggest to please use or buy a Latch not the Debounce Button/Switch to avoid problem.

Thanks,

Josh

Your giving the OP, wrong information. You clearly don't know the difference between debouncing a button and latching a button. I would love to fully explain the differences in detail, but this is something you need to research for yourself, THEN come back and see if the advice your giving is correct.

OP, if you want to debounce using hardware, google button debounce hardware. It is just a simple capacitor and resistor in the proper setup.