add one time mode measure delay

This commit is contained in:
Chris Laws
2017-09-02 10:39:30 +09:30
parent 8621e52340
commit 61455628d0
5 changed files with 37 additions and 20 deletions
+22 -5
View File
@@ -1,7 +1,6 @@
/*
This is a library for the BH1750FVI Digital Light Sensor
breakout board.
This is a library for the BH1750FVI Digital Light Sensor breakout board.
The BH1750 board uses I2C for communication. Two pins are required to
interface to the device. Configuring the I2C bus is expected to be done
@@ -118,19 +117,37 @@ void BH1750::configure(uint8_t mode) {
* Read light level from sensor
* @return Light level in lux (0 ~ 65535)
*/
uint16_t BH1750::readLightLevel(void) {
uint16_t BH1750::readLightLevel(bool maxWait) {
// Measurment result will be stored here
uint16_t level;
// One-Time modes apparently need to be re-applied after power-up
// to ensure the chip is awake.
// One-Time modes need to be re-applied after power-up. They have a maximum
// measurement time and a typical measurement time. The maxWait argument
// determines which measurement wait time is used when a one-time mode is
// being used. The typical (shorter) measurement time is used by default and
// if maxWait is set to True then the maximum measurement time will be used.
// See data sheet pages 2, 5 and 7 for more details.
switch (BH1750_MODE) {
case BH1750_ONE_TIME_HIGH_RES_MODE:
case BH1750_ONE_TIME_HIGH_RES_MODE_2:
case BH1750_ONE_TIME_LOW_RES_MODE:
// Send mode to sensor
Wire.beginTransmission(BH1750_I2CADDR);
__wire_write((uint8_t)BH1750_MODE);
Wire.endTransmission();
// wait for measurement time
if (BH1750_MODE == BH1750_ONE_TIME_LOW_RES_MODE) {
maxWait ? _delay_ms(24) : _delay_ms(16);
}
else {
maxWait ? _delay_ms(180) :_delay_ms(120);
}
break;
}
// Read two bytes from sensor
+1 -1
View File
@@ -63,7 +63,7 @@ class BH1750 {
BH1750 (byte addr = 0x23);
void begin (uint8_t mode = BH1750_CONTINUOUS_HIGH_RES_MODE);
void configure (uint8_t mode);
uint16_t readLightLevel(void);
uint16_t readLightLevel(bool maxWait = false);
private:
int BH1750_I2CADDR;
+4 -5
View File
@@ -25,10 +25,10 @@ Each mode, has three different precisions:
- High Resolution Mode 2 - (0.5 lx precision, 120ms measurment time)
By default, this library uses Continuous High Resolution Mode, but you can set
any other mode by definepassing the mode argument to BH1750.begin().
any other mode by passing the mode argument to BH1750.begin().
Remember, if you use One-Time mode, your sensor will go to Power Down mode
each time, when it completes measurment and you've read it.
Remember, if you use One-Time mode, your sensor will go into Power Down mode
when it completes the measurment and you've read it.
Typical Connection:
@@ -43,8 +43,7 @@ ADD pin is used to set sensor I2C address. If it has voltage greater or equal to
0x5C. In other case (if ADD voltage less than 0.7 * VCC) the sensor address will
be 0x23 (by default).
The datasheet for the BH1750 can be obtained [here](http://rohmfs.rohm.com/en/products/databook/datasheet/ic/sensor/light/bh1750fvi-e.pdf)
The datasheet for the BH1750 can be obtained [here](http://www.elechouse.com/elechouse/images/product/Digital%20light%20Sensor/bh1750fvi-e.pdf)
## Example
+8 -7
View File
@@ -2,7 +2,7 @@
Advanced BH1750 library usage example
This example had some comments about advanced usage features.
This example has some comments about advanced usage features.
Connection:
@@ -46,8 +46,8 @@ void setup(){
BH1750 has six different measurment modes. They are divided in two groups -
continuous and one-time measurments. In continuous mode, sensor continuously
measures lightness value. And in one-time mode, sensor makes only one
measurment, and going to Power Down mode after this.
measures lightness value. In one-time mode the sensor makes only one
measurment and then goes into Power Down mode.
Each mode, has three different precisions:
@@ -55,11 +55,12 @@ void setup(){
- High Resolution Mode - (1 lx precision, 120ms measurment time)
- High Resolution Mode 2 - (0.5 lx precision, 120ms measurment time)
By default, library use Continuous High Resolution Mode, but you can set
any other mode, by define it to BH1750.begin() or BH1750.configure() functions.
By default, the library uses Continuous High Resolution Mode, but you can
set any other mode, by passing it to BH1750.begin() or BH1750.configure()
functions.
[!] Remember, if you use One-Time mode, your sensor will go to Power Down mode
each time, when it completes measurment and you've read it.
[!] Remember, if you use One-Time mode, your sensor will go to Power Down
mode each time, when it completes measurment and you've read it.
Full mode list:
+2 -2
View File
@@ -2,8 +2,8 @@
Example of BH1750 library usage.
This example initalises the BH1750 object using the default
high resolution mode and then makes a light level reading every second.
This example initalises the BH1750 object using the default high resolution
continuous mode and then makes a light level reading every second.
Connection: