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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/OneButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -280,7 +297,7 @@ void OneButton::_fsm(bool activeLevel)
_idleState = true;
_idleFunc();
}

// waiting for level to become active.
if (activeLevel) {
_newState(OneButton::OCS_DOWN);
Expand Down
13 changes: 11 additions & 2 deletions src/OneButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 -----

Expand Down
Loading