fix broken header

This commit is contained in:
cm committed 2018-07-31 09:07:45 +02:00
1 parent 13dfed8a12
commit 95f46e599e
4 files changed
+82 -15

No files matched your search

+15 -2
View File
@@ -36,6 +36,9 @@
// Reset data register value - not accepted in POWER_DOWN mode
#define BH1750_RESET 0x07
// Default MTreg value
#define BH1750_DEFAULT_MTREG 69
class BH1750 {
public:
@@ -60,15 +63,25 @@ class BH1750 {
BH1750(byte addr = 0x23);
bool begin(Mode mode = CONTINUOUS_HIGH_RES_MODE);
bool configure(Mode mode);
bool setMTreg(byte MTreg);
#ifndef BH1750_FLOAT
uint16_t readLightLevel(bool maxWait = false);
int32_t readLightLevel(bool maxWait = false, bool hundredth = false);
#endif
#ifdef BH1750_FLOAT
float readLightLevel(bool maxWait = false);
#endif
private:
int BH1750_I2CADDR;
byte BH1750_I2CADDR;
byte BH1750_MTreg = (byte)BH1750_DEFAULT_MTREG;
// Correction factor used to calculate lux. Typical value is 1.2 but can range from 0.96 to 1.44.
// See data sheet (p.2, Measurement Accuracy) for more information.
#ifndef BH1750_FLOAT
const uint8_t BH1750_CONV_FACTOR = 12;
#endif
#ifdef BH1750_FLOAT
const float BH1750_CONV_FACTOR = 1.2;
#endif
Mode BH1750_MODE = UNCONFIGURED;
};
+13 -12
View File
@@ -46,13 +46,14 @@ Usually you will get an integer value which represent the lux equivalent.
The sensor returns a 16 bit unsigned integer. Therefore the maximum value is limited in general.
The standard conversion between the so called 'counts' to lux is 1/1.2, that means you get a smaller value.
If a error occurs you will get a positive value closely to the max.
- 65534 (65535-1) no valid data was transmitted from the sensor
- 65533 (65535-2) device is not configured
If you use the float, you get:
If a error occurs you will get a negative value.
As we use signed integer or float, if an error occurs you will get a negative value.
- -1 no valid data was transmitted from the sensor
- -2 device is not configured
As the sensor counts impact of light in a specific time frame you could change this time frame.
This is needed if you use an overlay windows or compensate environmental influence like darkness.
This time frame is defined by a register which is called MTreg. Therefore you could choose a value between 32 and 254.
The default value is 69; keep in mind that the measurement time is changed accordingly.
The datasheet for the BH1750 chip can be obtained [here](http://www.elechouse.com/elechouse/images/product/Digital%20light%20Sensor/bh1750fvi-e.pdf)
@@ -146,12 +147,12 @@ void loop() {
Moving the sensor to face more light results in the lux measurements increasing.
```
BH1750 Test
Light: 70 lx
Light: 70 lx
Light: 59 lx
Light: 328 lx
Light: 333 lx
Light: 335 lx
Light: 332 lx
Light: 70.0 lx
Light: 70.0 lx
Light: 59.0 lx
Light: 328.0 lx
Light: 333.0 lx
Light: 335.0 lx
Light: 332.0 lx
```
There are more examples in the examples directory.
@@ -0,0 +1,52 @@
/*
Example of BH1750 library usage.
This example initialises the BH1750 object using the default high resolution
continuous mode and then makes a light level reading every second.
Connection:
VCC -> 3V3 or 5V
GND -> GND
SCL -> SCL (A5 on Arduino Uno, Leonardo, etc or 21 on Mega and Due, on esp8266 free selectable)
SDA -> SDA (A4 on Arduino Uno, Leonardo, etc or 20 on Mega and Due, on esp8266 free selectable)
ADD -> (not connected) or GND
ADD pin is used to set sensor I2C address. If it has voltage greater or equal to
0.7VCC voltage (e.g. you've connected it to VCC) the sensor address will be
0x5C. In other case (if ADD voltage less than 0.7 * VCC) the sensor address will
be 0x23 (by default).
*/
#include <Wire.h>
#include <BH1750.h>
BH1750 lightMeter;
void setup(){
Serial.begin(9600);
// Initialize the I2C bus (BH1750 library doesn't do this automatically)
Wire.begin();
// On esp8266 you can select SCL and SDA pins using Wire.begin(D4, D3);
lightMeter.begin();
Serial.println(F("BH1750 Test begin"));
}
void loop() {
float lux = lightMeter.readLightLevel();
Serial.print("Light: ");
Serial.print(lux);
Serial.println(" lx");
delay(1000);
}
+2 -1
View File
@@ -14,9 +14,9 @@ BH1750 KEYWORD1
begin KEYWORD2
configure KEYWORD2
setMTreg KEYWORD2
readLightLevel KEYWORD2
#######################################
# Instances (KEYWORD2)
#######################################
@@ -31,3 +31,4 @@ BH1750_CONTINUOUS_LOW_RES_MODE LITERAL1
BH1750_ONE_TIME_HIGH_RES_MODE LITERAL1
BH1750_ONE_TIME_HIGH_RES_MODE_2 LITERAL1
BH1750_ONE_TIME_LOW_RES_MODE LITERAL1
BH1750_DEFAULT_MTREG LITERAL1