BH1750 icon indicating copy to clipboard operation
BH1750 copied to clipboard

`begin()` no longer overwrites previous address assignments by default

Open QuentinTorg opened this issue 1 year ago • 0 comments

Currently, if the user specifies a custom address to the BH1750 constructor, it will be overridden when the user calls the begin() function. I believe this was the root of the problem for #64. Two sensors were being used on the bus. The user was attempting to specify the override address in the constructor for the second sensor, but it was being overridden when calling begin()

example:

BH1750 sensor(0x5C); // initialize sensor with 0x5C
sensor.begin(); // library overwrites 0x5C address with 0x23 default parameter

This PR fixes the behavior by redefining the default address in the begin call with 0x00. This way the address is only overridden if the user supplies a non-zero address. The constructor already specifies a default 0x23 address, so it is guaranteed that the BH1750_I2CADDR will either have a value of 0x23 or the user-specified value by the time begin() is called

QuentinTorg avatar Aug 18 '23 18:08 QuentinTorg