Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
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 );
}
}