Skip to content

convertTimeToMTreg

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

convertTimeToMtreg

For this function the sensor needs to be calibrated!

From a needed conversion time in milliseconds, a matching MTreg is calculated.

 byte convertTimeToMtreg(unsigned int time, BH1750Quality quality);

result byte

A matching MTreg for a given time.
If the calculated MTreg is higher than BH1750_MTREG_HIGH = 254, the function returns 255 (0xFF).
If the calculated MTreg is lower than BH1750_MTREG_LOW = 31, the function returns 0 = zero. See example below.


Parameter int time

The sampling time in milliseconds


Parameter BH1750Quality quality

The Quality for which the MTreg should be calculated.
Qualities are BH1750_QUALITY_HIGH, BH1750_QUALITY_HIGH2, BH1750_QUALITY_LOW.


Hints:

Sometimes you want to measure a certain period of time in milliseconds.
The weird timing concept of this sensor make it nearly impossible.
With this useful function you can convert a MTreg into a time in milliseconds.

  BH1750.calibrateTimings(); //best placed into setup
  byte hundred = BH1750.convertTimeToMtreg(100,HIGH);
  if (hundred>= BH1750_MTREG_LOW && hundred <= BH1750_MTREG_HIGH) start(BH1750_QUALITY_HIGH, hundred);

If you have two sensors with a different timing behavior and want them to measure the same time period:

Example:

b1.calibrateSettings();
b2.calibrateSettings();
int time_ms=100;
b1.start(HIGH2, b1.convertTimeToMtreg(time_ms,BH1750_QUALITY_HIGH2));
b2.start(HIGH2, b2.convertTimeToMtreg(time_ms,BH1750_QUALITY_HIGH2));

You do not need to worry, if the calculated value is not within the allowed range, as function start will adjust the value for you.
All values above 254 will be 254 and all values below BH1750_MTREG_LOW will be BH1750_MTREG_LOW.

Please ensure, to start a measurement with the same quality, you obtained from the calculation.

The smallest and largest time that can be achieved, is chip dependent.

The "typical" range for Quality BH1750_QUALITY_LOW is between 7ms and 59 ms.
For Quality BH1750_QUALITY_HIGH and BH1750_QUALITY_HIGH2 it is between 54ms and 442 ms.

But this depends on the particular sensor.

Clone this wiki locally