Erriez BH1750 library for Arduino  1.1.2
This is a GY-302 breakout with an I2C BH1750 digital light sensor.
ErriezBH1750.h
Go to the documentation of this file.
1 /*
2  * MIT License
3  *
4  * Copyright (c) 2020 Erriez
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 #ifndef ERRIEZ_BH1750_H__
34 #define ERRIEZ_BH1750_H__
35 
36 #include <Arduino.h>
37 #include <Wire.h>
38 
40 typedef enum {
41  ModeContinuous = 0x10,
42  ModeOneTime = 0x20,
44 
46 typedef enum {
47  ResolutionLow = 0x03,
48  ResolutionMid = 0x00,
49  ResolutionHigh = 0x01,
51 
53 class BH1750
54 {
55 public:
56  explicit BH1750(uint8_t addrPinLevel=LOW);
57  void begin(BH1750_Mode_e mode, BH1750_Resolution_e resolution);
58  void powerDown();
59  void startConversion();
60  bool isConversionCompleted();
61  bool waitForCompletion();
62  uint16_t read();
63 
64 protected:
65  void writeInstruction(uint8_t instruction);
66  void setTimestamp();
67 
68 private:
69  unsigned long _completionTimestamp;
70  uint8_t _i2cAddr;
71  uint8_t _mode;
72 };
73 
74 #endif // ERRIEZ_BH1750_H__
BH1750_Resolution_e
Resolution register bits.
Definition: ErriezBH1750.h:46
bool waitForCompletion()
Wait for completion.
4 lx resolution
Definition: ErriezBH1750.h:47
One-time mode.
Definition: ErriezBH1750.h:42
BH1750_Mode_e
Mode register bits.
Definition: ErriezBH1750.h:40
void writeInstruction(uint8_t instruction)
Write instruction to sensor.
Continues mode.
Definition: ErriezBH1750.h:41
BH1750(uint8_t addrPinLevel=LOW)
Constructor.
void powerDown()
Power down. Call startConversion() to power-up automatically.
1 lx resolution
Definition: ErriezBH1750.h:48
BH1750 class.
Definition: ErriezBH1750.h:53
void begin(BH1750_Mode_e mode, BH1750_Resolution_e resolution)
Set mode and resolution.
void setTimestamp()
Save current time + minimum delay before reading next conversion in ms.
0.5 lx resolution
Definition: ErriezBH1750.h:49
bool isConversionCompleted()
Wait for completion.
uint16_t read()
Read light level asynchronous from sensor The application is responsible for wait or checking a compl...
void startConversion()
Start conversion.