Erriez BH1750 library for Arduino  1.1.2
This is a GY-302 breakout with an I2C BH1750 digital light sensor.
ErriezBH1750_regs.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_REGS_H_
34 #define ERRIEZ_BH1750_REGS_H_
35 
36 // I2C addresses (without R/W bit)
37 #define BH1750_I2C_ADDR_L 0x23
38 #define BH1750_I2C_ADDR_H 0x5C
39 
40 // Instructions
41 #define BH1750_POWER_DOWN 0x00
42 #define BH1750_POWER_ON 0x01
43 #define BH1750_RESET 0x07
44 
45 // Bitfields
46 #define BH1750_MODE_MASK 0x30
47 #define BH1750_RES_MASK 0x03
48 
49 // Worst case conversion timing in ms
50 #define BH1750_CONV_TIME_L 24
51 #define BH1750_CONV_TIME_H 180
52 
53 
57 #define IS_INITIALIZED(mode) (((mode) & BH1750_MODE_MASK) != 0x00)
58 
63 #define IS_CONTINUES_MODE(mode) (((mode) & BH1750_MODE_MASK) == ModeContinuous)
64 
69 #define IS_ONE_TIME_MODE(mode) (((mode) & BH1750_MODE_MASK) == ModeOneTime)
70 
75 #define IS_LOW_RESOLUTION(mode) (((mode) & BH1750_RES_MASK) == ResolutionLow)
76 
81 #define GET_TIMEOUT(mode) ((((mode) & BH1750_RES_MASK) == ResolutionLow) ? \
82  BH1750_CONV_TIME_L : BH1750_CONV_TIME_H)
83 
84 #endif // ERRIEZ_BH1750_REGS_H_