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.beginTransmission(0x44); Wire1.write(0x09); Wire1.endTransmission(); Wire1.beginTransmission(0x44); Wire1.requestFrom(0x44, 2); data = Wire1.read(); data |= (Wire1.read() << 8); Wire1.endTransmission(); 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?