Skip to content

Commit e261039

Browse files
fix pcf8574 setup
1 parent 93d2aff commit e261039

File tree

6 files changed

+11
-21
lines changed

6 files changed

+11
-21
lines changed

Button_PCF8574/Button_PCF8574.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ Button_PCF8574::Button_PCF8574(
1313
Method callback
1414
) {
1515
_btnPin = btn_pin;
16-
_pcf = pcf;
16+
_expander = pcf;
1717
_callback = callback;
1818
_lastBtnState = LOW;
1919
}
2020

2121
void Button_PCF8574::begin() {
22+
_expander->pinMode(_btnPin, INPUT);
2223
}
2324

2425
void Button_PCF8574::loop() {

Button_PCF8574/Button_PCF8574.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Button_PCF8574
2828
int _currentBtnState;
2929
int _lastBtnState;
3030
Method _callback;
31-
MultiPlexer_PCF8574* _pcf;
31+
MultiPlexer_PCF8574* _expander;
3232
unsigned long _lastDebounceTime = 0;
3333
unsigned long _debounceDelay = 5;
3434
};

LED_PCF8574/LED_PCF8574.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ LED_PCF8574::LED_PCF8574(
1313
int led_state
1414
) {
1515
_pin = pin;
16-
_pcf = pcf;
16+
_expander = pcf;
1717
state = led_state;
1818
}
1919

2020
void LED_PCF8574::begin() {
21-
_pcf->pinMode(_pin, OUTPUT);
21+
_expander->pinMode(_pin, OUTPUT, state);
2222
}
2323

2424
void LED_PCF8574::loop() {
2525
}
2626

2727
void LED_PCF8574::update() {
28-
_pcf->digitalWrite(_pin, state);
28+
_expander->digitalWrite(_pin, state);
2929
}
3030

3131
void LED_PCF8574::enable() {

LED_PCF8574/LED_PCF8574.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class LED_PCF8574
2929
void update();
3030

3131
int _pin;
32-
MultiPlexer_PCF8574* _pcf;
32+
MultiPlexer_PCF8574* _expander;
3333
};
3434

3535
#endif

MultiPlexer_PCF8574/MultiPlexer_PCF8574.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,13 @@
77

88
#include <MultiPlexer_PCF8574.h>
99

10-
MultiPlexer_PCF8574::MultiPlexer_PCF8574(uint8_t address) {
11-
_expander = new PCF8574(address);
10+
MultiPlexer_PCF8574::MultiPlexer_PCF8574(uint8_t address, uint8_t sda, uint8_t scl) {
11+
_expander = new PCF8574(address, sda, scl);
1212
}
1313

1414
void MultiPlexer_PCF8574::begin() {
1515
Serial.print("Initializing PCF8574... ");
1616

17-
/*
18-
// inputs
19-
int i = 0;
20-
for (i = 0; i<4; i++) {
21-
_expander->pinMode(i, INPUT);
22-
}
23-
// outputs
24-
for (i=4; i<8; i++) {
25-
_expander->pinMode(i, OUTPUT, LOW);
26-
}
27-
*/
28-
2917
if (_expander->begin()) {
3018
Serial.println("OK");
3119
} else{

MultiPlexer_PCF8574/MultiPlexer_PCF8574.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
class MultiPlexer_PCF8574
1515
{
1616
public:
17-
MultiPlexer_PCF8574(uint8_t address);
17+
MultiPlexer_PCF8574(uint8_t address, uint8_t sda, uint8_t scl);
1818
void begin();
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);
2222

2323
private:
2424
PCF8574* _expander;
25+
2526
};
2627

2728
#endif

0 commit comments

Comments
 (0)