I've been playing with this library for a DAC chip that I found on github. The default I2c addr for the DAC is 0x60, which is declared in the private member of the library. (It is also a parameter in multiple functions in the library) I was just using the example code hideakitai provided on github.
private:
struct DACInputData
{
VREF vref;
PWR_DOWN pd;
GAIN gain;
uint16_t data;
};
const uint8_t I2C_ADDR {0x60};
uint8_t addr_ {I2C_ADDR};
uint8_t pin_ldac_;
DACInputData reg_[4];
DACInputData eep_[4];
DACInputData read_reg_[4];
DACInputData read_eep_[4];
TwoWire* wire_;
};
Now I have multiple same DACs hooked up to photon, and I renamed their address so it's ranging from 0x60 to 0x67. I would like to be able to change the address from my main code , and then call the function to read the specific DAC.
So far, I have tried the following methods.
- Moving the "uint8_t I2C_ADDR;" from the private to the public, and then declare it in global in my main code "uint8_t I2C_ADDR = {0x63};". This returns the error
uninitialized const member in 'class MCP4728'
-
I removed the const and tried again, this time the code compiles but from the serial monitor, it seems like it's not reading the address and cannot print out any readings.
-
I used "extern uint8_t I2C_ADDR;" instead in the library. The error this time is
storage class specified for 'I2C_ADDR'
which is probably because there are lots of functions in the library that's like "function(I2C_ADDR){} which is illegal.
I'm really new to c++, any advice would be appreciated, thanks!