I2C libs, selecting multiple

Status
Not open for further replies.

drjohnsmith

Well-known member
I have a procedure, that uses the I2C on the teensey 3.6

I use all four of the available I2C's on the board,

At the moment, I have three procedures,
one for each of the I2C, which are remarkably similar,
one talks to wire, one to wire1, etc..

This is Ok,
but it strikes me that I should be able to code once and re use,

i.e. pass to the procedure the fact I want wire, or wire1 or ... etc

but, can't think how to do,

currently only 'solution' which is worse than the problem,
is to pass in a number 0 to 3 , that on each time I use the I2C lib in the procedure is used to select one of four cases,

very messy,

Any suggestions please
 
Not to hard...

You can do something like:
Code:
void my_function(TwoWire *my_wire) {
    my_wire->beginTransmission(...)
    my_wire->requestFrom(...)

Then you can call like:
Code:
    my_function(&Wire);
    my_function(&Wire1);
...
You might also be able to do it by passing a reference instead of by pointer...
 
Status
Not open for further replies.
Back
Top