1 | /*
|
---|
2 | * Digital_Light_TSL2561.h
|
---|
3 | * A library for TSL2561
|
---|
4 | *
|
---|
5 | * Copyright (c) 2012 seeed technology inc.
|
---|
6 | * Website : www.seeed.cc
|
---|
7 | * Author : zhangkun
|
---|
8 | * Create Time:
|
---|
9 | * Change Log :
|
---|
10 | *
|
---|
11 | * The MIT License (MIT)
|
---|
12 | *
|
---|
13 | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
---|
14 | * of this software and associated documentation files (the "Software"), to deal
|
---|
15 | * in the Software without restriction, including without limitation the rights
|
---|
16 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
---|
17 | * copies of the Software, and to permit persons to whom the Software is
|
---|
18 | * furnished to do so, subject to the following conditions:
|
---|
19 | *
|
---|
20 | * The above copyright notice and this permission notice shall be included in
|
---|
21 | * all copies or substantial portions of the Software.
|
---|
22 | *
|
---|
23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
---|
24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
---|
25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
---|
26 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
---|
27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
---|
28 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
---|
29 | * THE SOFTWARE.
|
---|
30 | */
|
---|
31 | #ifndef Digital_Light_TSL2561_H
|
---|
32 | #define Digital_Light_TSL2561_H
|
---|
33 |
|
---|
34 | #include <Arduino.h>
|
---|
35 |
|
---|
36 | #define TSL2561_Control 0x80
|
---|
37 | #define TSL2561_Timing 0x81
|
---|
38 | #define TSL2561_Interrupt 0x86
|
---|
39 | #define TSL2561_Channal0L 0x8C
|
---|
40 | #define TSL2561_Channal0H 0x8D
|
---|
41 | #define TSL2561_Channal1L 0x8E
|
---|
42 | #define TSL2561_Channal1H 0x8F
|
---|
43 |
|
---|
44 | #define TSL2561_Address 0x29 //device address
|
---|
45 |
|
---|
46 | #define LUX_SCALE 14 // scale by 2^14
|
---|
47 | #define RATIO_SCALE 9 // scale ratio by 2^9
|
---|
48 | #define CH_SCALE 10 // scale channel values by 2^10
|
---|
49 | #define CHSCALE_TINT0 0x7517 // 322/11 * 2^CH_SCALE
|
---|
50 | #define CHSCALE_TINT1 0x0fe7 // 322/81 * 2^CH_SCALE
|
---|
51 |
|
---|
52 | #define K1T 0x0040 // 0.125 * 2^RATIO_SCALE
|
---|
53 | #define B1T 0x01f2 // 0.0304 * 2^LUX_SCALE
|
---|
54 | #define M1T 0x01be // 0.0272 * 2^LUX_SCALE
|
---|
55 | #define K2T 0x0080 // 0.250 * 2^RATIO_SCA
|
---|
56 | #define B2T 0x0214 // 0.0325 * 2^LUX_SCALE
|
---|
57 | #define M2T 0x02d1 // 0.0440 * 2^LUX_SCALE
|
---|
58 | #define K3T 0x00c0 // 0.375 * 2^RATIO_SCALE
|
---|
59 | #define B3T 0x023f // 0.0351 * 2^LUX_SCALE
|
---|
60 | #define M3T 0x037b // 0.0544 * 2^LUX_SCALE
|
---|
61 | #define K4T 0x0100 // 0.50 * 2^RATIO_SCALE
|
---|
62 | #define B4T 0x0270 // 0.0381 * 2^LUX_SCALE
|
---|
63 | #define M4T 0x03fe // 0.0624 * 2^LUX_SCALE
|
---|
64 | #define K5T 0x0138 // 0.61 * 2^RATIO_SCALE
|
---|
65 | #define B5T 0x016f // 0.0224 * 2^LUX_SCALE
|
---|
66 | #define M5T 0x01fc // 0.0310 * 2^LUX_SCALE
|
---|
67 | #define K6T 0x019a // 0.80 * 2^RATIO_SCALE
|
---|
68 | #define B6T 0x00d2 // 0.0128 * 2^LUX_SCALE
|
---|
69 | #define M6T 0x00fb // 0.0153 * 2^LUX_SCALE
|
---|
70 | #define K7T 0x029a // 1.3 * 2^RATIO_SCALE
|
---|
71 | #define B7T 0x0018 // 0.00146 * 2^LUX_SCALE
|
---|
72 | #define M7T 0x0012 // 0.00112 * 2^LUX_SCALE
|
---|
73 | #define K8T 0x029a // 1.3 * 2^RATIO_SCALE
|
---|
74 | #define B8T 0x0000 // 0.000 * 2^LUX_SCALE
|
---|
75 | #define M8T 0x0000 // 0.000 * 2^LUX_SCALE
|
---|
76 |
|
---|
77 |
|
---|
78 |
|
---|
79 | #define K1C 0x0043 // 0.130 * 2^RATIO_SCALE
|
---|
80 | #define B1C 0x0204 // 0.0315 * 2^LUX_SCALE
|
---|
81 | #define M1C 0x01ad // 0.0262 * 2^LUX_SCALE
|
---|
82 | #define K2C 0x0085 // 0.260 * 2^RATIO_SCALE
|
---|
83 | #define B2C 0x0228 // 0.0337 * 2^LUX_SCALE
|
---|
84 | #define M2C 0x02c1 // 0.0430 * 2^LUX_SCALE
|
---|
85 | #define K3C 0x00c8 // 0.390 * 2^RATIO_SCALE
|
---|
86 | #define B3C 0x0253 // 0.0363 * 2^LUX_SCALE
|
---|
87 | #define M3C 0x0363 // 0.0529 * 2^LUX_SCALE
|
---|
88 | #define K4C 0x010a // 0.520 * 2^RATIO_SCALE
|
---|
89 | #define B4C 0x0282 // 0.0392 * 2^LUX_SCALE
|
---|
90 | #define M4C 0x03df // 0.0605 * 2^LUX_SCALE
|
---|
91 | #define K5C 0x014d // 0.65 * 2^RATIO_SCALE
|
---|
92 | #define B5C 0x0177 // 0.0229 * 2^LUX_SCALE
|
---|
93 | #define M5C 0x01dd // 0.0291 * 2^LUX_SCALE
|
---|
94 | #define K6C 0x019a // 0.80 * 2^RATIO_SCALE
|
---|
95 | #define B6C 0x0101 // 0.0157 * 2^LUX_SCALE
|
---|
96 | #define M6C 0x0127 // 0.0180 * 2^LUX_SCALE
|
---|
97 | #define K7C 0x029a // 1.3 * 2^RATIO_SCALE
|
---|
98 | #define B7C 0x0037 // 0.00338 * 2^LUX_SCALE
|
---|
99 | #define M7C 0x002b // 0.00260 * 2^LUX_SCALE
|
---|
100 | #define K8C 0x029a // 1.3 * 2^RATIO_SCALE
|
---|
101 | #define B8C 0x0000 // 0.000 * 2^LUX_SCALE
|
---|
102 | #define M8C 0x0000 // 0.000 * 2^LUX_SCALE
|
---|
103 | class TSL2561_CalculateLux
|
---|
104 | {
|
---|
105 | public:
|
---|
106 | signed long readVisibleLux();
|
---|
107 | unsigned long calculateLux(unsigned int iGain, unsigned int tInt,int iType);
|
---|
108 | void getLux(void);
|
---|
109 | void init(void);
|
---|
110 | uint8_t readRegister(int deviceAddress, int address);
|
---|
111 | void writeRegister(int deviceAddress, int address, uint8_t val);
|
---|
112 | private:
|
---|
113 | uint8_t CH0_LOW,CH0_HIGH,CH1_LOW,CH1_HIGH;
|
---|
114 | uint16_t ch0,ch1;
|
---|
115 | unsigned long chScale;
|
---|
116 | unsigned long channel1;
|
---|
117 | unsigned long channel0;
|
---|
118 | unsigned long ratio1;
|
---|
119 | unsigned int b;
|
---|
120 | unsigned int m;
|
---|
121 | unsigned long temp;
|
---|
122 | unsigned long lux;
|
---|
123 |
|
---|
124 | };
|
---|
125 | extern TSL2561_CalculateLux TSL2561;
|
---|
126 | #endif
|
---|
127 |
|
---|
128 |
|
---|