Adafruit Library
WipperSnapper_I2C_Driver_BH1750.h
1 #ifndef WipperSnapper_I2C_Driver_BH1750_H
2 #define WipperSnapper_I2C_Driver_BH1750_H
3 
5 #include <hp_BH1750.h> //include the library for the BH1750 sensor
6 
7 /**************************************************************************/
19 /**************************************************************************/
21 public:
22  /*******************************************************************************/
30  /*******************************************************************************/
31  WipperSnapper_I2C_Driver_BH1750(TwoWire *i2c, uint16_t sensorAddress)
32  : WipperSnapper_I2C_Driver(i2c, sensorAddress) {
33  _i2c = i2c;
34  _sensorAddress = sensorAddress;
35  }
36 
37  /*******************************************************************************/
41  /*******************************************************************************/
43  // Called when a BH1750 component is deleted.
44  delete _bh1750;
45  }
46 
47  /*******************************************************************************/
53  /*******************************************************************************/
54  bool begin() {
55  _bh1750 = new hp_BH1750();
56  // attempt to initialize BH1750
57  if (!_bh1750->begin(_sensorAddress, _i2c))
58  return false;
59  // Set to the recommended quality setting
60  _bh1750->setQuality(BH1750_QUALITY_HIGH);
61  return true;
62  }
63 
64  /*******************************************************************************/
74  /*******************************************************************************/
75  bool getEventLight(sensors_event_t *lightEvent) {
76  _bh1750->start();
77  lightEvent->light = _bh1750->getLux();
78  return true;
79  }
80 
81 protected:
82  hp_BH1750 *_bh1750;
83 };
84 
85 #endif // WipperSnapper_I2C_Driver_BH1750
WipperSnapper_I2C_Driver_BH1750(TwoWire *i2c, uint16_t sensorAddress)
Constructor for a BH1750 sensor.
Definition: WipperSnapper_I2C_Driver_BH1750.h:31
bool begin()
Initializes the BH1750 sensor and begins I2C. The set the quality to the H-Resolution Mode...
Definition: WipperSnapper_I2C_Driver_BH1750.h:54
Class that provides a driver interface for a BH1750 Light sensor.
Definition: WipperSnapper_I2C_Driver_BH1750.h:20
bool getEventLight(sensors_event_t *lightEvent)
Performs a light sensor read using the One Time Measurement feature of the BH1750. The sensor goes to Power Down mode after each reading.
Definition: WipperSnapper_I2C_Driver_BH1750.h:75
Base class for I2C Drivers.
Definition: WipperSnapper_I2C_Driver.h:30
uint16_t _sensorAddress
The I2C driver&#39;s unique I2C address.
Definition: WipperSnapper_I2C_Driver.h:1322
hp_BH1750 * _bh1750
Pointer to BH1750 light sensor object.
Definition: WipperSnapper_I2C_Driver_BH1750.h:82
~WipperSnapper_I2C_Driver_BH1750()
Destructor for a BH1750 sensor.
Definition: WipperSnapper_I2C_Driver_BH1750.h:42
TwoWire * _i2c
Pointer to the I2C driver&#39;s Wire object.
Definition: WipperSnapper_I2C_Driver.h:1321