Skip to content

Commit 1e6b267

Browse files
committed
Use int pin_mode instead of bool pullupActive.
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
1 parent 27da5fd commit 1e6b267

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/OneButton.cpp

+20-2
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,30 @@ OneButton::OneButton()
2929
// further initialization has moved to OneButton.h
3030
}
3131

32+
OneButton::OneButton(const int pin, const boolean activeLow, const int pin_mode)
33+
{
34+
_pin = pin;
35+
36+
if (activeLow) {
37+
// the button connects the input pin to GND when pressed.
38+
_buttonPressed = LOW;
39+
40+
} else {
41+
// the button connects the input pin to VCC when pressed.
42+
_buttonPressed = HIGH;
43+
}
44+
45+
// use the given pin in input mode aka INPUT, INPUT_PULLUP, INPUT_PULLDOWN according to the Arduino board.
46+
pinMode(pin, pin_mode);
47+
} // OneButton
48+
3249
/**
3350
* Initialize the OneButton library.
3451
* @param pin The pin to be used for input from a momentary button.
3552
* @param activeLow Set to true when the input level is LOW when the button is pressed, Default is true.
3653
* @param pullupActive Activate the internal pullup when available. Default is true.
3754
*/
55+
/*
3856
OneButton::OneButton(const int pin, const boolean activeLow, const bool pullupActive)
3957
{
4058
_pin = pin;
@@ -56,7 +74,7 @@ OneButton::OneButton(const int pin, const boolean activeLow, const bool pullupAc
5674
pinMode(pin, INPUT);
5775
}
5876
} // OneButton
59-
77+
*/
6078

6179
// explicitly set the number of millisec that have to pass by before a click is assumed stable.
6280
void OneButton::setDebounceMs(const unsigned int ms)
@@ -261,7 +279,7 @@ void OneButton::_fsm(bool activeLevel)
261279
_idleState = true;
262280
_idleFunc();
263281
}
264-
282+
265283
// waiting for level to become active.
266284
if (activeLevel) {
267285
_newState(OneButton::OCS_DOWN);

src/OneButton.h

+11-2
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,21 @@ class OneButton
4242
OneButton();
4343

4444
/**
45-
* Initialize the OneButton library.
45+
* Initialize the OneButton object.
46+
* @param pin The pin to be used for input from a momentary button.
47+
* @param activeLow Set to true when the input level is LOW when the button is pressed, Default is true.
48+
* @param pin_mode The pinMode() function parameter. INPUT, INPUT_PULLUP, INPUT_PULLDOWN etc. Default is INPUT_PULLUP.
49+
*/
50+
explicit OneButton(const int pin, const boolean activeLow = true, const int pin_mode = INPUT_PULLUP);
51+
52+
/**
53+
* Initialize the OneButton library. [deprecated]
4654
* @param pin The pin to be used for input from a momentary button.
4755
* @param activeLow Set to true when the input level is LOW when the button is pressed, Default is true.
4856
* @param pullupActive Activate the internal pullup when available. Default is true.
4957
*/
50-
explicit OneButton(const int pin, const boolean activeLow = true, const bool pullupActive = true);
58+
[[deprecated("Use OneButton(int pin, boolean activeLow, int pin_mode) instead.")]]
59+
/*explicit */OneButton(const int pin, const boolean activeLow/* = true*/, const bool pullupActive/* = true*/); // deprecated
5160

5261
// ----- Set runtime parameters -----
5362

0 commit comments

Comments
 (0)