claws / BH1750

An Arduino library for the digital light sensor breakout boards containing the BH1750FVI IC
MIT License
252 stars 108 forks source link

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

Open QuentinTorg opened 1 year ago

QuentinTorg commented 1 year ago

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