Skip to content

Commit 2bace1c

Browse files
committed
Add a helper function for inverted digitalRead
1 parent 8872190 commit 2bace1c

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

examples/debounce/debounce.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ void setup() {
1919
// Typical usage: with a normal digital input
2020
button = new DebounceFilter(filter_functions::ForDigitalRead<kButtonPin>());
2121

22+
// For an inverted input, e.g. when using a button with a pullup resistor
23+
button = new DebounceFilter(filter_functions::ForInvertedDigitalRead<kButtonPin>());
24+
2225
// Advanced usage: custom input function
2326
button = new DebounceFilter(readButtonPin);
2427

src/filter.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ static bool (*ForDigitalRead())() {
181181
return []() { return (bool)digitalRead(pin); };
182182
}
183183

184+
template <uint32_t pin>
185+
static bool (*ForInvertedDigitalRead())() {
186+
return []() { return (bool)!digitalRead(pin); };
187+
}
188+
184189
template <uint32_t pin>
185190
static uint32_t (*ForAnalogRead())() {
186191
return []() { return (uint32_t)analogRead(pin); };

0 commit comments

Comments
 (0)