mirror of
https://github.com/claws/BH1750.git
synced 2026-09-22 18:21:48 +00:00
example added
This commit is contained in:
1 parent
95f46e599e
commit
a30562d278
1 file changed
+30
-9
@@ -25,16 +25,16 @@
|
||||
|
||||
BH1750 lightMeter;
|
||||
|
||||
|
||||
void setup(){
|
||||
|
||||
Serial.begin(9600);
|
||||
Serial.begin(115200);
|
||||
|
||||
// Initialize the I2C bus (BH1750 library doesn't do this automatically)
|
||||
Wire.begin();
|
||||
Wire.begin(D2, D1);
|
||||
// On esp8266 you can select SCL and SDA pins using Wire.begin(D4, D3);
|
||||
|
||||
lightMeter.begin();
|
||||
lightMeter.begin(BH1750::ONE_TIME_HIGH_RES_MODE);
|
||||
//lightMeter.setMTreg(69); //not needed, only mentioning it
|
||||
|
||||
Serial.println(F("BH1750 Test begin"));
|
||||
|
||||
@@ -42,11 +42,32 @@ void setup(){
|
||||
|
||||
|
||||
void loop() {
|
||||
|
||||
float lux = lightMeter.readLightLevel();
|
||||
Serial.print("Light: ");
|
||||
//we use here the maxWait option due fail save and we want reduced information loss due missing decimal part
|
||||
float lux = lightMeter.readLightLevel(true, true)/100.0;
|
||||
if (lux > 40000.0) {
|
||||
//reduce time slot - needed in direct sun light
|
||||
if(lightMeter.setMTreg(32)) {
|
||||
Serial.println(F("[DEBUG]: MTReg low"));
|
||||
lux = lightMeter.readLightLevel(true, true)/100.0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(lux > 10.0 && lightMeter.setMTreg(69)) {
|
||||
Serial.println(F("[DEBUG]: MTReg default"));
|
||||
lux = lightMeter.readLightLevel(true, true)/100.0;
|
||||
}
|
||||
}
|
||||
if (lux <= 10.0) {
|
||||
//very low light environment
|
||||
if(lightMeter.setMTreg(254)) {
|
||||
Serial.println(F("[DEBUG]: MTReg high"));
|
||||
lux = lightMeter.readLightLevel(true, true)/100.0;
|
||||
}
|
||||
}
|
||||
Serial.print(F("Light: "));
|
||||
Serial.print(lux);
|
||||
Serial.println(" lx");
|
||||
delay(1000);
|
||||
Serial.println(F(" lx"));
|
||||
Serial.println(F("--------------------------------------"));
|
||||
delay(5000);
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user