Skip to content

setTimeout

Stefan Armborst edited this page Jan 27, 2020 · 10 revisions

setTimeout


Sets a timeout, to wait if no valid value at the estimated time measured.
This only happens if the raw data result is zero (below 0.11 Lux at Quality BH1750_QUALITY_HIGH2 and MTreg = 254).

Changing this value, does not affect a current running measurement.
The timeout is not affected by setTimeOffset().


  void setTimeout(int timeout);

Result void


Parameter int timeout

Sets the timeout in milliseconds.
Yes, even a negative value is possible, but almost senseless.


Explanation

When a measurement is started, the last value, that is stored in the sensor is set to zero (0).
See reset() and working principle.

If you ask the sensor directly after a measurement was started, you will get the value zero (0)
Until you get no value higher than zero (0), the measurement is not finished yet.

This works very well, but what if the new value is really zero, because it is very dark?
As we know the conversion time, we can assume that this value is really zero!
But even with a calibrated sensor, the conversion time may differ a little. See here.
So, to be sure to get a brightness of zero, we can use a adjustable timeout.

What happens after you start a measurement and ask the sensor for a new value?

In non-blocking mode with getValue(), the sensor will wait until the estimated conversion time is over.
Then it will do the first true reading to the chip.
In almost all cases, it will obtain the new value.
But if the value is zero then the sensor asks for a new value until the value is higher than zero, or the timeout is over. After timeout is over, you will get the brightness "0" (zero).

The default value of timeout is 10 ms, but even 3 ms will work fine for me.

Clone this wiki locally