loading

How to use Multiple mcp23017 chips with the adafruit mcp23017.h library?

I have been experimenting with I2C and the mcp23017 IO expander chip for my arduino ATMega2560 as I would rather use the IO on the arduino its self for other things I am just figuring out how to use the adafruit mcp23017.h library and cant figure out how to address multiple mcp23017 chips and how to use there pins individually this is the code from the button library that I editied.

Here is the datesheet of mcp23017

I want to be able to address the individual chips and the pins I was not quite sure if in the setup that the pin modes for the IO go up sequentially from 0 past 15 if multiple chips are connected and addressed in code. For example if the first chip is addressed as 0x20 and the IO number count is from 0 - 15 if I added and addressed another chip as 0x21 will that count go from 0 - 15 to 0 - 31. ~ Edit if you could recommend or send a library that would be easier or could help please do.

#include <Wire.h>
#include "Adafruit_MCP23017.h"

//pin 1 and 0 are mcp pins not arduino IO pins

Adafruit_MCP23017 mcp;

void setup() { 
mcp.begin();      // use default address 0

mcp.pinMode(0, INPUT);
mcp.pinMode(1, OUTPUT);
Serial.begin(9600);

pinMode(13, OUTPUT);  // use the p13 LED as debugging
}



void loop() {
// The LED will 'echo' the button
digitalWrite(13, mcp.digitalRead(0)); //Writes pin 13 to the reading of pin    0
mcp.digitalWrite(1, mcp.digitalRead(0)); //Writes pin 1 to the reading of 0
if(mcp.digitalRead(1) == HIGH){ //if pin 1 == high serialprint led whent   high
Serial.println("Led whent HIGH");
}
}

Try it and see what happens.