OneButton icon indicating copy to clipboard operation
OneButton copied to clipboard

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

Open IhorNehrutsa opened this issue 1 year ago • 1 comments

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

IhorNehrutsa avatar Mar 08 '24 20:03 IhorNehrutsa

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 avatar Mar 08 '24 21:03 IhorNehrutsa

Please remove unused code. Please also update the documentation (README, CHANGELOG) Any changes in examples required ?

mathertel avatar Jul 31 '24 18:07 mathertel

I found another solution for you using the new setup(...) function . See #129

mathertel avatar Aug 01 '24 17:08 mathertel