diff --git a/src/OneButton.cpp b/src/OneButton.cpp index 0a83bb3..86c00ef 100644 --- a/src/OneButton.cpp +++ b/src/OneButton.cpp @@ -29,6 +29,23 @@ OneButton::OneButton() // further initialization has moved to OneButton.h } +OneButton::OneButton(const int pin, const boolean activeLow, const int pin_mode) +{ + _pin = pin; + + if (activeLow) { + // the button connects the input pin to GND when pressed. + _buttonPressed = LOW; + + } else { + // the button connects the input pin to VCC when pressed. + _buttonPressed = HIGH; + } + + // use the given pin in input mode aka INPUT, INPUT_PULLUP, INPUT_PULLDOWN according to the Arduino board. + pinMode(pin, pin_mode); +} // OneButton + /** * Initialize the OneButton library. * @param pin The pin to be used for input from a momentary button. @@ -56,7 +73,7 @@ OneButton::OneButton(const int pin, const bool activeLow, const bool pullupActiv pinMode(pin, INPUT); } } // OneButton - +*/ // explicitly set the number of millisec that have to pass by before a click is assumed stable. void OneButton::setDebounceMs(const int ms) @@ -280,7 +297,7 @@ void OneButton::_fsm(bool activeLevel) _idleState = true; _idleFunc(); } - + // waiting for level to become active. if (activeLevel) { _newState(OneButton::OCS_DOWN); diff --git a/src/OneButton.h b/src/OneButton.h index a706c10..ccb553f 100644 --- a/src/OneButton.h +++ b/src/OneButton.h @@ -42,12 +42,21 @@ class OneButton OneButton(); /** - * Initialize the OneButton library. + * Initialize the OneButton object. + * @param pin The pin to be used for input from a momentary button. + * @param activeLow Set to true when the input level is LOW when the button is pressed, Default is true. + * @param pin_mode The pinMode() function parameter. INPUT, INPUT_PULLUP, INPUT_PULLDOWN etc. Default is INPUT_PULLUP. + */ + explicit OneButton(const int pin, const boolean activeLow = true, const int pin_mode = INPUT_PULLUP); + + /** + * Initialize the OneButton library. [deprecated] * @param pin The pin to be used for input from a momentary button. * @param activeLow Set to true when the input level is LOW when the button is pressed, Default is true. * @param pullupActive Activate the internal pullup when available. Default is true. */ - explicit OneButton(const int pin, const bool activeLow = true, const bool pullupActive = true); + [[deprecated("Use OneButton(int pin, bool activeLow, int pin_mode) instead.")]] + /*explicit */OneButton(const int pin, const bool activeLow/* = true*/, const bool pullupActive/* = true*/); // deprecated // ----- Set runtime parameters -----