Digital 16bit Serial Output Type Ambient Light Sensor IC by ROHM, Ambient light sensor (Illuminance to digital converter). Forked from Kenji Arai BH1750, minor changes.
Diff: BH1750.h
- Revision:
- 3:3c15665641ff
- Parent:
- 2:74dba61588ed
- Child:
- 4:47d7e70dc9b8
--- a/BH1750.h Thu Sep 12 10:51:25 2019 +0000 +++ b/BH1750.h Fri Sep 13 12:51:31 2019 +0000 @@ -3,11 +3,11 @@ * light intensity sensor module with built-in a 16 bit AD converter generating digital signal. * BH1750 by ROHM Co.,Ltd. * - * Copyright (c) 2015,'17 Kenji Arai / JH1PJL - * http://www.page.sannet.ne.jp/kenjia/index.html - * http://mbed.org/users/kenjiArai/ - * Created: March 7th, 2015 - * Revised: August 23rd, 2017 + * Copyright (c) 2019, Mauricio Donatti / LNLS (Brazilian Synchrotron Light Source + * https://os.mbed.com/users/mmdonatti/ + * https://www.linkedin.com/in/mauriciodonatti + * Created: September 2019 + * Revised: September 2019 */ /* *---------------- REFERENCE ---------------------------------------------------------------------- @@ -15,6 +15,9 @@ * http://www.rohm.co.jp/web/japan/products/-/product/BH1750FVI * Device kit * http://www.aitendo.com/product/10240 + * Initial Credits to Kenji Arai / JH1PJL (Forked from Kenji's library) + * http://www.page.sannet.ne.jp/kenjia/index.html + * http://mbed.org/users/kenjiArai/ */ #ifndef BH1750_H @@ -41,32 +44,35 @@ #define CMD_M_TIME_L 0x60 ////////////// SENSITIVITY //////////////////////////////// -#define SENS_1R00 69 -#define SENS_3R68 254 +#define SENS_1R00 69 //Default +#define SENS_3R68 254 //High Sensitivity #define SENS_0R45 31 #define SENS_2R00 138 #define SENS_0R50 35 /** Interface for Luminosity sensor, BH1750 - * @code - * #include "mbed.h" - * #include "BH1750.h" - * - * // I2C Communication - * BH1750 lum(dp5,dp27); // BH1750 SDA, SCL - * // If you connected I2C line not only this device but also other devices, - * // you need to declare following method. - * I2C i2c(dp5,dp27); // SDA, SCL - * BH1750 lum(i2c); // BH1750 SDA, SCL (Data available every 120mSec) - * - * int main() {; - * while(true){ - * printf("Illuminance: %+7.2f [Lux]\r\n", lum.lux()); - * wait(1.0); - * } - * } - * @endcode - */ +//@code +#include "mbed.h" +#include "BH1750.h" +// I2C Communication +BH1750 lum(dp5,dp27); // BH1750 SDA, SCL +//If you connected I2C line not only this device but also other devices, +//you need to declare following method. +//I2C i2c(dp5,dp27); // SDA, SCL +//BH1750 lum(i2c); // BH1750 SDA, SCL (Data available every 120mSec) + +int main() { + lum.set_high_resolution(SENS_1R00); + //or + //lum.set_high_resolution_2(SENS_1R00); + + while(true){ + printf("Illuminance: %+7.2f [Lux]\r\n", lum.lux()); + wait(1.0); + } +} +//@endcode +*/ class BH1750 { @@ -89,11 +95,17 @@ */ float lux(void); - /** Set sensor sensitivity adjustment + /** Set sensor to high resolution mode * @param sensitivity parameter * @return none */ - void set_sensitivity(uint8_t parameter); + void set_high_resolution(uint8_t parameter); + + /** Set sensor to high resolution mode + * @param sensitivity parameter + * @return none + */ + void set_high_resolution_2(uint8_t parameter); /** Set I2C clock frequency * @param freq. @@ -117,6 +129,7 @@ private: uint8_t BH1750_addr; uint8_t dt[4]; + uint8_t Hres; int8_t sensitivity; };