Go Down

Topic: Bounce (and Bounce 2) Library Official Question Forum (Read 26705 times) previous topic - next topic

tof

Bounce is a library for Arduino.
It debounces* digital inputs and more.

Bounce has passed from version 1 to version 2.
Version 2 is released but also in development.
Basically version 2 adds a better setup interface and matches the behavior requested by many (I still like the initial debounce algorithm and you can revert to the initial algorithm if you prefer).

The download is here :  https://github.com/thomasfredericks/Bounce-Arduino-Wiring/archive/master.zip
The documentation is here : https://github.com/thomasfredericks/Bounce-Arduino-Wiring/wiki
The playground page is here : http://playground.arduino.cc/code/bounce
The github is here : https://github.com/thomasfredericks/Bounce-Arduino-Wiring

Please ask questions here instead of my personal email.

* : http://en.wikipedia.org/wiki/Debounce#Contact_bounce|debounces
Thomas Ouellet Fredericks

tof

Quote
hi , i have a project that a simple button trigger a loop ( for() ) and after the loop is completed once, the debouncer do it again like i pushed the button again , do you have a command to clear it please ?


You are misinterpreting what debouncing is.

Quote
ok i think if i change debouncer.read(); by debouncer.fell(); can be solved ?


Yes.

read() returns the debounced (aka filtered) current state of the pin.

fell() and rose() return 1 when the pin went from HIGH to LOW (fell) or went from LOW to HIGH (rose) since the last update.
Thomas Ouellet Fredericks

Alnoa

ok if i m well understanding , read() is filtering the input with the interval(), then fell() and rise() arent ?
http://www.alnoa.fr

tof

fell() and rise() are also filtered.

read() returns the filtered state of the input : HIGH or LOW

fell() returns 1 if the filtered state went from HIGH to LOW since the last update. Returns 0 if not.

rose()  returns 1 if the filtered state went from LOW to HIGH since the last update. Returns 0 if not.

If you are only interested in state changes use fell() and rose().
Thomas Ouellet Fredericks

Alnoa


fell() and rise() are also filtered.

read() returns the filtered state of the input : HIGH or LOW

fell() returns 1 if the filtered state went from HIGH to LOW since the last update. Returns 0 if not.

rose()  returns 1 if the filtered state went from LOW to HIGH since the last update. Returns 0 if not.

If you are only interested in state changes use fell() and rose().

Thanks :)
http://www.alnoa.fr

InnoUPG

Does your loop() need to execute very fast for the bouncer.update function to work properly? Suppose you wanted a debounce interval of 10 mS,  but your loop() has other code that will (or could) take longer than that to execute; or you had a delay(50) at the end of each loop. Am I correct that the debouncing would have no benefit in this case? It seems like reading of the switch would become completely unreliable -- you might be reading (and debouncing) noise or true signal?

Second, your documentation says the debounce interval (interval_millis) is a unsigned long (integer); but your header file says it's a uint16_t, which is a regular unsigned int. I guess it's not a problem as long as the math with this number and millis() which is a long, uint32_t, works OK. But it would be better if documentation were consistent with code.

BLRP

Hi, I'm using bounce2 for a project I'm working on. I'm using push buttons as a bump switch or limit swich to control the direction of a DC motor. I'm very close to achieving my goal, however, right now the program is not switching until I release the momentary push button. I need it to switch at the very press of the button.

Do I need to change the bounce library & if so, how?

Thanks, BLRP

JimboZA

My guess is that you're looking for the wrong transition. You're looking for a high when you should be looking for a low, or vice versa: depends how the switch is wired.

But that's a guess: as always, you get a better answer with more info: post sketch and schematic.
Johannesburg hams call me: ZS6JMB on Highveld rep 145.7875 (-600 & 88.5 tone)
Dr Perry Cox: "Help me to help you, help me to help you...."
Your answer may already be here: https://forum.arduino.cc/index.php?topic=384198.0

BLRP

OK, my sketch (ICarV10.ino) is attached below, it is a slightly modified version of Steven Cogswell's Relay Shield Library using the Relay Shield found here
Pins 4-7 control the  4relays & pins 8-11 sense the push buttons which use the arduino's 5v & a resistor to ground


JimboZA

I meant a schematic of the whole thing: presumably the buttons take the pins to ground?
Johannesburg hams call me: ZS6JMB on Highveld rep 145.7875 (-600 & 88.5 tone)
Dr Perry Cox: "Help me to help you, help me to help you...."
Your answer may already be here: https://forum.arduino.cc/index.php?topic=384198.0

BLRP

I meant a schematic of the whole thing: presumably the buttons take the pins to ground?
Yes, they use the arduino's 5v & a resistor to ground

JimboZA

Yes, they use the arduino's 5v & a resistor to ground
That doesn't makes sense: you enabled the internal pullups in the code as well..... you don't use both.

Pretty please, let's see a schematic.....
Johannesburg hams call me: ZS6JMB on Highveld rep 145.7875 (-600 & 88.5 tone)
Dr Perry Cox: "Help me to help you, help me to help you...."
Your answer may already be here: https://forum.arduino.cc/index.php?topic=384198.0

JimboZA

If you have the button to 5V as it sounds like, that's going to override the internal pullup. Your external resistor is a pulldown. So there you have classic "active high" behaviour: you see high when the button is pushed, not the low that your sketch is looking for; the low only happens when you let go.

If you want classic "active low", keep the internal pullup enabled as you have, and ditch the external resistor and conenction to 5V (if that's what you have...)

Johannesburg hams call me: ZS6JMB on Highveld rep 145.7875 (-600 & 88.5 tone)
Dr Perry Cox: "Help me to help you, help me to help you...."
Your answer may already be here: https://forum.arduino.cc/index.php?topic=384198.0

BLRP

OK, here's the schematic, sorry, not the best.

So how would I change the program since I've already soldered my shield board?

JimboZA

The pic is fine: any pic is better than words.

So as I thought, you have a classic "pulldown" setup there, hardware-wise.

That means the button is low most of the time, and high when pressed. Your sketch is looking for a low, though. If you want stuff to happen when the button is pressed, that means you need to look for a high.

So change your logic to be an "if.... == high" instead of the current "==low"

You can also lose the lines that enables the internal pullups, ie the digitalWrite highs.

Disclaimer: I have not checked every line of that code so be sure this is what you want to do. YMMV, E&OE, Ts and Cs apply....
Johannesburg hams call me: ZS6JMB on Highveld rep 145.7875 (-600 & 88.5 tone)
Dr Perry Cox: "Help me to help you, help me to help you...."
Your answer may already be here: https://forum.arduino.cc/index.php?topic=384198.0

Go Up