Reading multiple ports with SoftwareWire


I’m using the SoftwareWire library to read multiple sensors using the wire protocol. The thing is it’s 6 sensors and sending and reading bytes for each one of them gives an enormous amount of lines.

I have a function called ReadGreen that returns an int:

  uint16_t data = 0x0000;
  Wire1.requestFrom(0x44, 2);
  data =;
  data |= ( << 8);
  return data;

As you can see, the ports are declared as Wire1. But I’d have to repeat the same code for Wire2, 3 and so on.

Is there some way to change that number? So I can do a for loop and write and read from Wire[n] and reduce the amount of lines?


Since you left out much of the relevant code I would have to guess that you have six I2C/TWI/Wire devices for which you can't set any address other than 0x44. To talk to them separately you are using a software implementation of the I2C/TWI/Wire protocol on various pins.

You should be able to create an array of SoftwareWire objects.

Show ALL of your code and I might be able to figure it out without my having to track down the SoftwareWire library.