-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBH1750.ino
49 lines (32 loc) · 865 Bytes
/
BH1750.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <BH1750.h>
BH1750 lightMeter;
uint8_t bh_module_num;
bool bh_boot ( uint8_t mybootnum ) {
bh_module_num = mybootnum;
tcaselect(TCA_BH1);
if (!lightMeter.begin(BH1750::ONE_TIME_HIGH_RES_MODE)) return false;
return true;
}
void bh_read () {
if (!ModuleData[bh_module_num].Register.ModuleDetected) return;
tcaselect(TCA_BH1);
if (lightMeter.measurementReady(true)) {
float lux = lightMeter.readLightLevel();
SensorData.bhData.LightLevel = lux;
if (lux > 40000.0) {
lightMeter.setMTreg(32);
return;
}
if (lux > 10.0) {
lightMeter.setMTreg(69);
return;
}
if (lux <= 10.0) {
lightMeter.setMTreg(138);
return;
}
}
}
void bh_print () {
printf( "BH1: Lux[%.2f]\n", SensorData.bhData.LightLevel );
}