Library for BH1750 I2C light sensor. Supports autoranging! True to datasheet. (beware: calls are blocking at the moment)
sample program
#include "mbed.h" #include "BH1750.h" I2C i2c(PB_9, PB_8); // SDA, SCL on Nucleo BH1750 light(i2c, true); // ##true## means we want autoranging be active Serial pc(USBTX, USBRX, 57600); int main() { light.power(true); // turn on light.setMtreg(BH1750::DEFAULTMTREG); // just to set defaults light.setMode(BH1750::CONTINOUS_H_RES_CMD); while (1) { float lux = light.read(); pc.printf("luminosity: %.1f lx\r\n", lux); pc.printf("log(lx): %f\r\n\r\n", log10(lux + 1) /4.55 ); } }