diff --git a/BH1750.cpp b/BH1750.cpp index e7a2f30..ed48cf1 100644 --- a/BH1750.cpp +++ b/BH1750.cpp @@ -56,6 +56,20 @@ BH1750::BH1750(byte addr) { } +/** + * Begin I2C and configure sensor + * @param SDA Date SCL Clock mode Measurment mode + */ +#if defined(ARDUINO_ARCH_ESP8266) +void BH1750::begin(uint8_t SDA, uint8_t SCL, uint8_t mode) { + + // allow config of pins + Wire.begin(SDA,SCL); + + // Configure sensor in specified mode + configure(mode); +} +#endif /** * Begin I2C and configure sensor diff --git a/BH1750.h b/BH1750.h index 947283d..90dc4df 100644 --- a/BH1750.h +++ b/BH1750.h @@ -60,6 +60,10 @@ class BH1750 { public: BH1750 (byte addr = 0x23); + #if defined(ARDUINO_ARCH_ESP8266) + /* ==== On esp8266 it is possible to define I2C pins ==== */ + void begin (uint8_t SDA, uint8_t SCL, uint8_t mode = BH1750_CONTINUOUS_HIGH_RES_MODE); + #endif void begin (uint8_t mode = BH1750_CONTINUOUS_HIGH_RES_MODE); void configure (uint8_t mode); uint16_t readLightLevel(void); diff --git a/bh1750.patch b/bh1750.patch new file mode 100644 index 0000000..eb36042 --- /dev/null +++ b/bh1750.patch @@ -0,0 +1,40 @@ +diff --git a/BH1750.cpp b/BH1750.cpp +index e7a2f30..ed48cf1 100644 +--- a/BH1750.cpp ++++ b/BH1750.cpp +@@ -56,6 +56,20 @@ BH1750::BH1750(byte addr) { + + } + ++/** ++ * Begin I2C and configure sensor ++ * @param SDA Date SCL Clock mode Measurment mode ++ */ ++#if defined(ARDUINO_ARCH_ESP8266) ++void BH1750::begin(uint8_t SDA, uint8_t SCL, uint8_t mode) { ++ ++ // allow config of pins ++ Wire.begin(SDA,SCL); ++ ++ // Configure sensor in specified mode ++ configure(mode); ++} ++#endif + + /** + * Begin I2C and configure sensor +diff --git a/BH1750.h b/BH1750.h +index 947283d..90dc4df 100644 +--- a/BH1750.h ++++ b/BH1750.h +@@ -60,6 +60,10 @@ class BH1750 { + + public: + BH1750 (byte addr = 0x23); ++ #if defined(ARDUINO_ARCH_ESP8266) ++ /* ==== On esp8266 it is possible to define I2C pins ==== */ ++ void begin (uint8_t SDA, uint8_t SCL, uint8_t mode = BH1750_CONTINUOUS_HIGH_RES_MODE); ++ #endif + void begin (uint8_t mode = BH1750_CONTINUOUS_HIGH_RES_MODE); + void configure (uint8_t mode); + uint16_t readLightLevel(void);