Skip to content

tolerance as a parameter #6

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
7 changes: 4 additions & 3 deletions src/ezAnalogKeypad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@

#include <ezAnalogKeypad.h>

ezAnalogKeypad::ezAnalogKeypad(int pin) {
ezAnalogKeypad::ezAnalogKeypad(int pin, int _tolerance=100) {
keypadPin = pin;
tolerance = _tolerance;
debounceTime = 50; // default is 50ms

lastDebounceTime = 0;
Expand Down Expand Up @@ -87,12 +88,12 @@ unsigned char ezAnalogKeypad::getKey() {
int upper_bound;
for(int i = 0; i < keyNum; i++) {
if(i == 0)
lower_bound = values[i] - 100; // 100 is tolerance
lower_bound = values[i] - tolerance; // default tolerance value is 100
else
lower_bound = (values[i] + values[i-1]) / 2;

if(i == (keyNum - 1))
upper_bound = values[i] + 100; // 100 is tolerance
upper_bound = values[i] + tolerance; // default tolerance is 100
else
upper_bound = (values[i] + values[i+1]) / 2;

Expand Down
1 change: 1 addition & 0 deletions src/ezAnalogKeypad.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ezAnalogKeypad
private:
int keypadPin;
unsigned long debounceTime;
int tolerance;
unsigned long lastDebounceTime;
int keyNum;
int lastKeyId;
Expand Down