Moderators: adafruit_support_bill, adafruit
// Basic pin reading and pullup test for the MCP23017 I/O expander
// public domain!
// Connect pin #12 of the expander to Analog 5 (i2c clock)
// Connect pin #13 of the expander to Analog 4 (i2c data)
// Connect pins #15, 16 and 17 of the expander to ground (address selection)
// Connect pin #9 of the expander to 5V (power)
// Connect pin #10 of the expander to ground (common ground)
Finally, I'm assuming that the MCP23017 #2 output pins would be addressed as 16-31, #3 would be addressed as 32-47. Is this correct, or would I need to address the outputs differently?
Adafruit_MCP23017 mcp0;
Adafruit_MCP23017 mcp1;
Adafruit_MCP23017 mcp2;
void setup() {
mcp0.begin(0);
mcp1.begin(1);
mcp2.begin(2);
...combinedMCP.digitalWrite(1, HIGH);
thru
combinedMCP.digitalWrite(64, HIGH);
while(digitalRead(input)==1 && output < 31){
output++;
mcp.digitalWrite(output, HIGH);
delay(100);
}
mcpArray[output>>4].digitalWrite((output & 0x0F), HIGH);driverblock wrote:One way you could do it would be to declare an array of Adafruit_MCP23017 objects. Then, write an intermediate function that you call instead of mcp.digitalWrite(output, HIGH);
In the intermediate function, you can shift the output number right by 4 bits (i.e., divide by 16). That will give you the index to your array. Then you can perform a logical AND of the output with 0x0F to give you the local output address for the selected string.
So, your call to digitalWrite would look something like this:
- Code: Select all
mcpArray[output>>4].digitalWrite((output & 0x0F), HIGH);
Adafruit_MCP23017 mcpArray[2];mcpArray[output>>4].digitalWrite((output & 0x0F), HIGH);driverblock wrote:Thanks for the vote! Sorry if it was a little too basic, but it's hard to know what level people are at, so I just tried to be thorough.
driverblock wrote:Thanks for the vote! Sorry if it was a little too basic, but it's hard to know what level people are at, so I just tried to be thorough.
A2 A1 A0 I2C address
---------------- --------------
GND GND GND 0x20
GND GND Vdd 0x21
GND Vdd GND 0x22
GND Vdd Vdd 0x23
Vdd GND GND 0x24
Vdd GND Vdd 0x25
Vdd Vdd GND 0x26
Vdd Vdd Vdd 0x27Return to Other Arduino products from Adafruit
Users browsing this forum: No registered users and 5 guests