press and hold #13

Closed
opened 2015-02-20 22:58:09 +03:00 by eadf · 18 comments
eadf commented 2015-02-20 22:58:09 +03:00 (Migrated from github.com)

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.
thomasfredericks commented 2015-02-23 22:42:25 +03:00 (Migrated from github.com)

I will look into it, but if I recall correctly, there was an issue with the BOUNCE_LOCK-OUT mode.

I will look into it, but if I recall correctly, there was an issue with the BOUNCE_LOCK-OUT mode.
eadf commented 2015-02-24 12:48:43 +03:00 (Migrated from github.com)

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.
MrHaroldA commented 2018-02-13 13:24:46 +03:00 (Migrated from github.com)

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.
thomasfredericks commented 2018-03-01 15:41:01 +03:00 (Migrated from github.com)

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.
thomasfredericks commented 2018-03-08 20:36:23 +03:00 (Migrated from github.com)

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?

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?
ducnvu commented 2018-09-07 11:53:11 +03:00 (Migrated from github.com)

Hi where is this previousDuration() I can't see it in the code

Hi where is this previousDuration() I can't see it in the code
MrHaroldA commented 2018-09-07 12:28:30 +03:00 (Migrated from github.com)

Can't find it either; but thank you for the reminder to check this out ;)

Can't find it either; but thank you for the reminder to check this out ;)
ducnvu commented 2018-09-07 13:46:31 +03:00 (Migrated from github.com)

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.
thomasfredericks commented 2018-09-11 17:11:18 +03:00 (Migrated from github.com)

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,
MrHaroldA commented 2018-11-12 23:25:50 +03:00 (Migrated from github.com)

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
ghost commented 2021-03-31 19:39:01 +03:00 (Migrated from github.com)

is there a duration() example?

is there a duration() example?
thomasfredericks commented 2021-04-02 00:21:08 +03:00 (Migrated from github.com)
Yes, in the examples. https://github.com/thomasfredericks/Bounce2/tree/master/examples/more/duration
pReya commented 2021-07-14 23:37:29 +03:00 (Migrated from github.com)

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?

> 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?
thomasfredericks commented 2021-07-18 13:26:56 +03:00 (Migrated from github.com)

Oups. Sorry. You are right. The example needs to be updated. I will do it once I get back from vacation.

Oups. Sorry. You are right. The example needs to be updated. I will do it once I get back from vacation.
pReya commented 2021-08-02 22:25:30 +03:00 (Migrated from github.com)

@thomasfredericks Not trying to annoy you on vaction ;) But I'd really appreciate a better example.

@thomasfredericks Not trying to annoy you on vaction ;) But I'd really appreciate a better example.
thomasfredericks commented 2021-08-03 18:02:31 +03:00 (Migrated from github.com)

No worries @pReya , I uploaded 3 new duration examples in the "examples/more" folder: https://github.com/thomasfredericks/Bounce2/tree/master/examples/more/

No worries @pReya , I uploaded 3 new duration examples in the "examples/more" folder: https://github.com/thomasfredericks/Bounce2/tree/master/examples/more/
thomasfredericks commented 2021-08-03 18:03:31 +03:00 (Migrated from github.com)

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
pReya commented 2021-08-04 10:20:32 +03:00 (Migrated from github.com)

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).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Max/thomasfredericks_Bounce2#13