diff --git a/src/MCP23017.cpp b/src/MCP23017.cpp index b36cb8f..edd69cd 100644 --- a/src/MCP23017.cpp +++ b/src/MCP23017.cpp @@ -5,6 +5,11 @@ MCP23017::MCP23017(uint8_t address, TwoWire& bus) { _bus = &bus; } +MCP23017::MCP23017(TwoWire& bus) { + _deviceAddr = MCP23017_I2C_ADDRESS; + _bus = &bus; +} + MCP23017::~MCP23017() {} void MCP23017::init() @@ -25,6 +30,17 @@ void MCP23017::init() writeRegister(MCP23017Register::GPPU_A, 0xFF, 0xFF); } +void MCP23017::begin() +{ + init(); +} + +void MCP23017::begin(uint8_t address) +{ + _deviceAddr = address; + begin(); +} + void MCP23017::portMode(MCP23017Port port, uint8_t directions, uint8_t pullups, uint8_t inverted) { writeRegister(MCP23017Register::IODIR_A + port, directions); diff --git a/src/MCP23017.h b/src/MCP23017.h index e665108..3427261 100644 --- a/src/MCP23017.h +++ b/src/MCP23017.h @@ -3,6 +3,7 @@ #include #include +#define MCP23017_I2C_ADDRESS 0x20 ///< The default I2C address of MCP23017. #define _MCP23017_INTERRUPT_SUPPORT_ ///< Enables support for MCP23017 interrupts. enum class MCP23017Port : uint8_t @@ -65,10 +66,24 @@ class MCP23017 * Instantiates a new instance to interact with a MCP23017 at the specified address. */ MCP23017(uint8_t address, TwoWire& bus = Wire); + /** + * Instantiates a new instance to interact with a MCP23017 at the + * MCP23017_I2C_ADDRESS default. + */ + MCP23017(TwoWire& bus = Wire); ~MCP23017(); #ifdef _DEBUG void debug(); #endif + /** + * Uses the I2C address set during construction. Implicitly calls init(). + */ + void begin(); + /** + * Overrides the I2C address set by the constructor. Implicitly calls begin(). + + */ + void begin(uint8_t address); /** * Initializes the chip with the default configuration. * Enables Byte mode (IOCON.BANK = 0 and IOCON.SEQOP = 1). @@ -221,4 +236,4 @@ class MCP23017 void clearInterrupts(uint8_t& portA, uint8_t& portB); #endif -}; \ No newline at end of file +};