Skip to content

Commit a45e9a6

Browse files
committed
Resolve #3 by adding readGPIO function to read single bank of IO.
1 parent 7c98808 commit a45e9a6

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Adafruit_MCP23017.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,25 @@ uint16_t Adafruit_MCP23017::readGPIOAB() {
150150
return ba;
151151
}
152152

153+
/**
154+
* Read a single port, A or B, and return its current 8 bit value.
155+
* Parameter b should be 0 for GPIOA, and 1 for GPIOB.
156+
*/
157+
uint8_t Adafruit_MCP23017::readGPIO(uint8_t b) {
158+
159+
// read the current GPIO output latches
160+
Wire.beginTransmission(MCP23017_ADDRESS | i2caddr);
161+
if (b == 0)
162+
wiresend(MCP23017_GPIOA);
163+
else {
164+
wiresend(MCP23017_GPIOB);
165+
}
166+
Wire.endTransmission();
167+
168+
Wire.requestFrom(MCP23017_ADDRESS | i2caddr, 1);
169+
return wirerecv();
170+
}
171+
153172
/**
154173
* Writes all the pins in one go. This method is very useful if you are implementing a multiplexed matrix and want to get a decent refresh rate.
155174
*/

Adafruit_MCP23017.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Adafruit_MCP23017 {
2727

2828
void writeGPIOAB(uint16_t);
2929
uint16_t readGPIOAB();
30+
uint8_t readGPIO(uint8_t b);
3031

3132
void setupInterrupts(uint8_t mirroring, uint8_t open, uint8_t polarity);
3233
void setupInterruptPin(uint8_t p, uint8_t mode);

0 commit comments

Comments
 (0)