Skip to content

Commit 5fdae20

Browse files
fix button reading
1 parent e261039 commit 5fdae20

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

Button_PCF8574/Button_PCF8574.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,26 @@ void Button_PCF8574::loop() {
2727
}
2828

2929
void Button_PCF8574::read() {
30-
/*
31-
int buttonReading = _mcp->getPin(_btnPin, _port);
30+
uint8_t buttonReading = _expander->digitalRead(_btnPin);
3231

3332
// if the switch changed, due to noise or pressing
3433
if (buttonReading != _lastBtnState) {
3534
// reset the debouncing timer
3635
_lastDebounceTime = millis();
3736
}
37+
3838
if ((millis() - _lastDebounceTime) > _debounceDelay) {
3939
// if the button state has changed
4040
if (buttonReading != _currentBtnState) {
4141
_currentBtnState = buttonReading;
4242

4343
// only toggle if the new button state is HIGH
4444
if (_currentBtnState == HIGH) {
45-
_callback.callbackIntArg(_btnPin);
45+
_callback.callback();
4646
}
4747
}
4848
}
49+
4950
// save the switch reading
5051
_lastBtnState = buttonReading;
51-
*/
52-
}
52+
}

Button_PCF8574/Button_PCF8574.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Button_PCF8574
3030
Method _callback;
3131
MultiPlexer_PCF8574* _expander;
3232
unsigned long _lastDebounceTime = 0;
33-
unsigned long _debounceDelay = 5;
33+
unsigned long _debounceDelay = 50;
3434
};
3535

3636
#endif

MultiPlexer_PCF8574/MultiPlexer_PCF8574.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@ void MultiPlexer_PCF8574::pinMode(uint8_t pin, uint8_t mode, uint8_t initialValu
3131
void MultiPlexer_PCF8574::digitalWrite(uint8_t pin, uint8_t value) {
3232
_expander->digitalWrite(pin, value);
3333
}
34+
35+
uint8_t MultiPlexer_PCF8574::digitalRead(uint8_t pin, bool forceReadNow) {
36+
_expander->digitalRead(pin, forceReadNow);
37+
}

MultiPlexer_PCF8574/MultiPlexer_PCF8574.h

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class MultiPlexer_PCF8574
1919
void loop();
2020
void pinMode(uint8_t pin, uint8_t mode, uint8_t initialValue = HIGH);
2121
void digitalWrite(uint8_t pin, uint8_t value);
22+
uint8_t digitalRead(uint8_t pin, bool forceReadNow = true);
2223

2324
private:
2425
PCF8574* _expander;

0 commit comments

Comments
 (0)