Skip to content

Commit 75c5e84

Browse files
use TwoWire instance
1 parent ea774ba commit 75c5e84

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

MultiPlexer_PCF8574/MultiPlexer_PCF8574.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
/* Copyright (c) 2020-2021, Collab
1+
/* Copyright (c) 2020-2023, Collab
22
* All rights reserved
33
*/
44

55
#include <MultiPlexer_PCF8574.h>
66

7-
MultiPlexer_PCF8574::MultiPlexer_PCF8574(uint8_t address, uint8_t sda, uint8_t scl) {
8-
_sdaPin = sda;
9-
_sclPin = scl;
10-
_expander = new PCF8574(address);
7+
MultiPlexer_PCF8574::MultiPlexer_PCF8574(uint8_t address, TwoWire* wire) {
8+
_expander = new PCF8574(address, wire);
119
}
1210

1311
bool MultiPlexer_PCF8574::begin() {
14-
return _expander->begin(_sdaPin, _sclPin);
12+
bool expanderReady = _expander->begin();
13+
if (!expanderReady) {
14+
Log.warning(F("PCF8574 could not initialize!" CR));
15+
}
16+
if (!isConnected()) {
17+
Log.warning(F("PCF8574 not connected!" CR));
18+
}
19+
return expanderReady;
1520
}
1621

1722
bool MultiPlexer_PCF8574::isConnected() {
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2020-2021, Collab
1+
/* Copyright (c) 2020-2023, Collab
22
* All rights reserved
33
*/
44
/*
@@ -8,22 +8,20 @@
88
#define MultiPlexer_PCF8574_h
99

1010
#include <Arduino.h>
11-
#include <Method.h>
1211
#include <PCF8574.h>
12+
#include <ArduinoLog.h>
1313

1414
class MultiPlexer_PCF8574
1515
{
1616
public:
17-
MultiPlexer_PCF8574(uint8_t address, uint8_t sda, uint8_t scl);
17+
MultiPlexer_PCF8574(uint8_t address, TwoWire* wire = &Wire);
1818
bool begin();
1919
bool isConnected();
2020
void digitalWrite(uint8_t pin, uint8_t value);
2121
uint8_t digitalRead(uint8_t pin);
2222

2323
private:
2424
PCF8574* _expander;
25-
uint8_t _sdaPin;
26-
uint8_t _sclPin;
2725
};
2826

2927
#endif

0 commit comments

Comments
 (0)