thomasfredericks / Bounce2

Debouncing library for Arduino and Wiring
MIT License
584 stars 172 forks source link

Invert #60

Closed NoobTracker closed 4 years ago

NoobTracker commented 4 years ago

This version adds the function setInvert (bool invert) with which you can invert the read values. This is practical for pins with INPUT_PULLUP, because you can work with buttons on these pins as well as with pins with INPUT. It is programmed to be backward compatible with older programs. It appears that I changed the whole program because I worked on it offline and then replaced the existing file at GitHub.

todo[bot] commented 4 years ago

Make Bounce2 more abstract. Split it from the hardware layer.

Remove deboucing code from Bounce2 and make a new Debounce class from that code. Bounce2 should extend Debounce.


https://github.com/thomasfredericks/Bounce2/blob/000f1fe060e5c18857e476b915e6dae60418854f/src/Bounce2.h#L30-L35


This comment was generated by todo based on a todo comment in 000f1fe060e5c18857e476b915e6dae60418854f in #60. cc @NoobTracker.
thomasfredericks commented 4 years ago

Thank you for your contribution, but Bounce2 does not encompass the notion of an elevated state akin to on/off, pressed or released in which case the inversion would be relevant. I will not merge but I suggest you extend the Bounce2 class instead to keep your modifications compatible.

NoobTracker commented 4 years ago

But isn't this lib primarily for debouncing buttons? At least that was why I downloaded it. And that is very useful, because if the program for pulldown resistors is made and you want to use the internal pullup resistors instead, you have to replace every fell with rose, every rose with felland every read with !read.

thomasfredericks commented 4 years ago

It is for any type of contact. Buttons are the primary use. But sometimes you don't push a button, you slide it, etc. I do not want to invert the HIGH or LOW states because that would not match the electrical reality. It is in the todo to make an extended class of Bounce2 specifically for buttons.

NoobTracker commented 4 years ago

Okay, you can cross that off the todo list.