Request: add Button class state output method isPressed() #69

Closed
opened 2020-08-25 19:24:05 +03:00 by EclipseBoom · 2 comments
EclipseBoom commented 2020-08-25 19:24:05 +03:00 (Migrated from github.com)

The Button class doesn't have a logically correct .read() method that takes the PressedState into account. The pressed() and released() methods are one-time changed state outputs. Sometimes I want to detect if a Button is being held down.

Something like isPressed() or isReleased() would make logical sense.

Thanks for your work on this library. So simple yet so useful.

The Button class doesn't have a logically correct .read() method that takes the PressedState into account. The pressed() and released() methods are one-time changed state outputs. Sometimes I want to detect if a Button is being held down. Something like isPressed() or isReleased() would make logical sense. Thanks for your work on this library. So simple yet so useful.
thomasfredericks commented 2020-08-25 21:20:17 +03:00 (Migrated from github.com)

Hi, the read returns the electrical state of the pin. This does not change with a pull-up or pull-down button circuit.

Does this merge meet your other needs? https://github.com/thomasfredericks/Bounce2/pull/67

Hi, the read returns the electrical state of the pin. This does not change with a pull-up or pull-down button circuit. Does this merge meet your other needs? https://github.com/thomasfredericks/Bounce2/pull/67
EclipseBoom commented 2020-08-25 23:28:10 +03:00 (Migrated from github.com)

Yes I understand the method from Bounce returns the electrical state of the pin. However, this could be opposite of the logical state of being pressed if the pressed state as LOW electrically which is the most common situation (and NOT the default BTW). Read() gives LOW=false when the button is pressed in the majority of cases. This basically makes the Button class useless because you can't use read() without knowing explicitly the electrical sense of the button. So if you have to know the physical connection explicitly why bother with the Button class at all? If you can abstract the electrical state by PressedState() in your definition section all your code will stay correct and abstracted if the hardware changes in the future which is, as I see it, the only real reason for Button in the first place.

Yes I understand the method from Bounce returns the electrical state of the pin. However, this could be opposite of the logical state of being pressed if the pressed state as LOW electrically which is the most common situation (and NOT the default BTW). Read() gives LOW=false when the button is pressed in the majority of cases. This basically makes the Button class useless because you can't use read() without knowing explicitly the electrical sense of the button. So if you have to know the physical connection explicitly why bother with the Button class at all? If you can abstract the electrical state by PressedState() in your definition section all your code will stay correct and abstracted if the hardware changes in the future which is, as I see it, the only real reason for Button in the first place.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Max/thomasfredericks_Bounce2#69