Skip to content
Open
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
19 changes: 11 additions & 8 deletions src/ezButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@

#include <ezButton.h>

ezButton::ezButton(int pin): ezButton(pin, INPUT_PULLUP) {};
ezButton::ezButton(int pin): ezButton(pin, INPUT_PULLUP, ACTIVE_LOW) {};

ezButton::ezButton(int pin, int mode) {
ezButton::ezButton(int pin, int mode): ezButton(pin, mode, ACTIVE_LOW) {};

ezButton::ezButton(int pin, int mode, int active) {
btnPin = pin;
activeMode = active;
debounceTime = 0;
count = 0;
countMode = COUNT_FALLING;
Expand All @@ -61,17 +64,17 @@ int ezButton::getStateRaw(void) {
}

bool ezButton::isPressed(void) {
if(previousSteadyState == HIGH && lastSteadyState == LOW)
return true;
if (activeMode == ACTIVE_LOW)
return (previousSteadyState == HIGH && lastSteadyState == LOW);
else
return false;
return (previousSteadyState == LOW && lastSteadyState == HIGH);
}

bool ezButton::isReleased(void) {
if(previousSteadyState == LOW && lastSteadyState == HIGH)
return true;
if (activeMode == ACTIVE_LOW)
return (previousSteadyState == LOW && lastSteadyState == HIGH);
else
return false;
return (previousSteadyState == HIGH && lastSteadyState == LOW);
}

void ezButton::setCountMode(int mode) {
Expand Down
4 changes: 4 additions & 0 deletions src/ezButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@
#define COUNT_RISING 1
#define COUNT_BOTH 2

#define ACTIVE_LOW 0
#define ACTIVE_HIGH 1

class ezButton
{
private:
int btnPin;
int activeMode;
unsigned long debounceTime;
unsigned long count;
int countMode;
Expand Down