I needed two functions in one button so added a duration() method to your class.
It simply returns the period [ms] the pin has been in current state (totally undisturbed - flatline)
If you think this is something you would like in your library i can make a pull request.
Or you can add it yourself, it's effectively a one-liner.
I needed two functions in one button so added a [`duration()` method ](https://github.com/eadf/Bounce2) to your class.
It simply returns the period [ms] the pin has been in current state (totally undisturbed - flatline)
If you think this is something you would like in your library i can make a pull request.
Or you can add it yourself, it's effectively a one-liner.
An alternative would be to keep another timestamp that remembers when the output value of the debouncer last changed.
Perhaps that's more semantically correct, a user of the debouncer who wants to know if the button has been pressed for 1 seconds or more doesn't care if there were some jitter 10ms ago. It's a debouncer after all.
An alternative would be to keep another timestamp that remembers when the output value of the debouncer last changed.
Perhaps that's more semantically correct, a user of the debouncer who wants to know if the button has been pressed for 1 seconds or more doesn't care if there were some jitter 10ms ago. It's a debouncer after all.
Isn't this as simple as to expose previous_millis as public? In my code I have to declare and fill my own variable to store exactly the same data to check if a switch is pressed long.
Anyway: this would be a very welcome addition for me.
Isn't this as simple as to expose `previous_millis` as public? In my code I have to declare and fill my own variable to store exactly the same data to check if a switch is pressed long.
Anyway: this would be a very welcome addition for me.
Isn't this as simple as to expose previous_millis as public? In my code I have to declare and fill my own variable to store exactly the same data to check if a switch is pressed long.
No. As @eadf notes, previous_millis is an internal timer that does not necessarily match the duration of a press.
If someone wants to code and test it, I will try to integrate it.
> Isn't this as simple as to expose previous_millis as public? In my code I have to declare and fill my own variable to store exactly the same data to check if a switch is pressed long.
No. As @eadf notes, previous_millis is an internal timer that does not necessarily match the duration of a press.
If someone wants to code and test it, I will try to integrate it.
duration() that returns how long the current state has been lasting
previousDuration() that returns how long the previous state lasted
What do you think?
Okay, in the new "duration" branch (https://github.com/thomasfredericks/Bounce2/tree/Duration) I added two methods:
* `duration()` that returns how long the current state has been lasting
* `previousDuration()` that returns how long the previous state lasted
What do you think?
Yeah I'm trying to implement a pressed button using duration() but can't get hold of it as it returns 0 whenever button move do you have any tip? I'm quite new to all of this.
Yeah I'm trying to implement a pressed button using duration() but can't get hold of it as it returns 0 whenever button move do you have any tip? I'm quite new to all of this.
This was implemented in a branch. It was removed when the branch was merged for release as it was not sufficiently tested. I added a test previousDuration() in the master branch,
This was implemented in a branch. It was removed when the branch was merged for release as it was not sufficiently tested. I added a test ```previousDuration()``` in the master branch,
I finally got the chance to test duration() and previousDuration() and they both work exactly like advertised! ;)
I managed to save 4 bytes of SRAM using them :D
I finally got the chance to test `duration()` and `previousDuration()` and they both work exactly like advertised! ;)
I managed to save 4 bytes of SRAM using them :D
Somehow, the example called duration.ino actually doesn't use the duration() function. Is this on purpose?
> Yes, in the examples. https://github.com/thomasfredericks/Bounce2/tree/master/examples/more/duration
Somehow, the example called `duration.ino` actually doesn't use the `duration()` function. Is this on purpose?
No worries @pReya , I uploaded 3 new duration examples in the "examples/more" folder: https://github.com/thomasfredericks/Bounce2/tree/master/examples/more/
Please note I changed duration() to currentDuration() to avoid any confusion.
currentDuration() = duration of current state
previousDuration() = duration of previous state
Please note I changed duration() to currentDuration() to avoid any confusion.
currentDuration() = duration of current state
previousDuration() = duration of previous state
Thank you so much! Appreciate it a lot. I think it would be a good idea to add the term "long press" or "button hold" to the folders/filenames/readme, because it's a term that's googled a lot. Might bring new users to the library (if that's what you're after).
Thank you so much! Appreciate it a lot. I think it would be a good idea to add the term "long press" or "button hold" to the folders/filenames/readme, because it's a term that's googled a lot. Might bring new users to the library (if that's what you're after).
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
I needed two functions in one button so added a
duration()method to your class.It simply returns the period [ms] the pin has been in current state (totally undisturbed - flatline)
If you think this is something you would like in your library i can make a pull request.
Or you can add it yourself, it's effectively a one-liner.
I will look into it, but if I recall correctly, there was an issue with the BOUNCE_LOCK-OUT mode.
An alternative would be to keep another timestamp that remembers when the output value of the debouncer last changed.
Perhaps that's more semantically correct, a user of the debouncer who wants to know if the button has been pressed for 1 seconds or more doesn't care if there were some jitter 10ms ago. It's a debouncer after all.
Isn't this as simple as to expose
previous_millisas public? In my code I have to declare and fill my own variable to store exactly the same data to check if a switch is pressed long.Anyway: this would be a very welcome addition for me.
No. As @eadf notes, previous_millis is an internal timer that does not necessarily match the duration of a press.
If someone wants to code and test it, I will try to integrate it.
Okay, in the new "duration" branch (https://github.com/thomasfredericks/Bounce2/tree/Duration) I added two methods:
duration()that returns how long the current state has been lastingpreviousDuration()that returns how long the previous state lastedWhat do you think?
Hi where is this previousDuration() I can't see it in the code
Can't find it either; but thank you for the reminder to check this out ;)
Yeah I'm trying to implement a pressed button using duration() but can't get hold of it as it returns 0 whenever button move do you have any tip? I'm quite new to all of this.
This was implemented in a branch. It was removed when the branch was merged for release as it was not sufficiently tested. I added a test
previousDuration()in the master branch,I finally got the chance to test
duration()andpreviousDuration()and they both work exactly like advertised! ;)I managed to save 4 bytes of SRAM using them :D
is there a duration() example?
Yes, in the examples. https://github.com/thomasfredericks/Bounce2/tree/master/examples/more/duration
Somehow, the example called
duration.inoactually doesn't use theduration()function. Is this on purpose?Oups. Sorry. You are right. The example needs to be updated. I will do it once I get back from vacation.
@thomasfredericks Not trying to annoy you on vaction ;) But I'd really appreciate a better example.
No worries @pReya , I uploaded 3 new duration examples in the "examples/more" folder: https://github.com/thomasfredericks/Bounce2/tree/master/examples/more/
Please note I changed duration() to currentDuration() to avoid any confusion.
currentDuration() = duration of current state
previousDuration() = duration of previous state
Thank you so much! Appreciate it a lot. I think it would be a good idea to add the term "long press" or "button hold" to the folders/filenames/readme, because it's a term that's googled a lot. Might bring new users to the library (if that's what you're after).