I have a bunch of code to setup an i2c sensor, etc. And each sensor could be on a different bus, and possibly different addresses.
So I want to reuse my code, and be able to change the code easily to handle different setups.
Here's my first basic attempt just to test the concept (it compiles), and just wanted to ask if this makes sense? Or if there is anything I should keep in mind. I know this is getting very tied into i2c_t3, but it seems the easiest way for me to do this.
So I want to reuse my code, and be able to change the code easily to handle different setups.
Here's my first basic attempt just to test the concept (it compiles), and just wanted to ask if this makes sense? Or if there is anything I should keep in mind. I know this is getting very tied into i2c_t3, but it seems the easiest way for me to do this.
Code:
#include <i2c_t3.h>
void setup() {
// put your setup code here, to run once:
setupWire(&Wire, I2C_PINS_18_19);
setupWire(&Wire1, I2C_PINS_22_23);
}
void setupWire(i2c_t3 *WireTmp, i2c_pins setupPins) {
WireTmp->begin(I2C_MASTER, 0x00, setupPins, I2C_PULLUP_EXT, I2C_RATE_100);
}
void loop() {
// put your main code here, to run repeatedly:
}