How do I get rid of duplication

It's not a bad idea, considering that there are a fixed number of I/O's on each expander IC. A somewhat pedantic method but possible, would be to make an array of expander I2C addresses and use the upper index bits to select the right one for the chosen row. It would make adding more expanders easier, as no changes to SetPWM() would be needed.

But that might point back to a 2 dimensional scheme, as the first dimension corresponds also to individual I2C devices. Possibly a struct, containing both the array and the I2C address?