Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use int pin_mode instead of bool pullupActive in OneButton() constructor. #138

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

IhorNehrutsa
Copy link
Contributor

Use constructor:
OneButton(const int pin, const boolean activeLow = true, const int pin_mode = INPUT_PULLUP);
instead of:
OneButton(const int pin, const boolean activeLow = true, const bool pullupActive = true);

Use the given pin in input mode aka INPUT, INPUT_PULLUP, INPUT_PULLDOWN according to the Arduino board.
Like in the native Arduino function:

pinMode(pin, mode);

For example:

#if defined(BUTTONS_PULLUP)
userButton = new OneButton(aPIN);
//or it is equivalent to
userButton = new OneButton(aPIN, true, INPUT_PULLUP); 

#elif defined(BUTTONS_PULLDOWN)
userButton = new OneButton(aPIN, false, INPUT_PULLDOWN); 

#elif defined(BUTTONS_HIGH_IMPEDANCE)
userButton = new OneButton(aPIN, true, INPUT);
#endif

explicit OneButton(const int pin, const boolean activeLow = true, const int pin_mode = INPUT_PULLUP);

[[deprecated("Use OneButton(int pin, boolean activeLow, int pin_mode) instead.")]]
OneButton(const int pin, const boolean activeLow, const bool pullupActive); // deprecated

For example:
#if defined(BUTTONS_PULLUP)
userButton = new OneButton(aPIN);
// it is equivalent to
userButton = new OneButton(aPIN, true, INPUT_PULLUP);
#elif defined(BUTTONS_PULLDOWN)
userButton = new OneButton(aPIN, false, INPUT_PULLDOWN);
#elif defined(BUTTONS_HIGH_IMPEDANCE)
userButton = new OneButton(aPIN, true, INPUT);
#endif
@IhorNehrutsa
Copy link
Contributor Author

Hi @mathertel Matthias.
First, I am glad to see new commits in OneButton lib.

Last time I used OneButton lib with ESP32 microcontroller under Arduino framework in PlatformIO.
ESP32 has INPUT_PULLDOWN mode in
Arduino pinMode(pin, mode) function.

This PR allows to use all pin modes.
Could you please review the proposed changes and give your opinion on this PR.
I can also correct lib examples and documentation.

Best regards.
Ihor.

@IhorNehrutsa IhorNehrutsa changed the title Use int pin_mode instead of bool pullupActive in OneButton() constructor. Use int pin_mode instead of bool pullupActive in OneButton() constructor. Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant