-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBH1750FVI.cpp
71 lines (54 loc) · 1.5 KB
/
BH1750FVI.cpp
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*****************************************************
Library for light intensity sensor BH1750FVI
Markus Ulsass, Hamburg, Germany
ulsass@tradewire.de
20-5-2016
https://github.com/markbeee/IKEA_hydroponics_control
******************************************************/
#include "Arduino.h"
#include "BH1750FVI.h"
BH1750FVI::BH1750FVI(){}
void BH1750FVI::begin(void){
Wire.begin();
i2cWrite(Power_On);
}
// Instruction set architecture modes (for details s. page 5 datasheet BH1750FVI)
void BH1750FVI::setMode(uint8_t mode){
switch(mode){
case Power_Down:
break;
case Power_On:
break;
case Reset:
break;
case Continuously_High_Resolution_Mode:
break;
case Continuously_High_Resolution_Mode2:
break;
case Continuously_Low_Resolution_Mode:
break;
case OneTime_High_Resolution_Mode:
break;
case OneTime_High_Resolution_Mode2:
break;
case OneTime_Low_Resolution_Mode:
break;
}
i2cWrite(mode);
}
void BH1750FVI::i2cWrite(uint8_t data){
Wire.beginTransmission(i2cAddress);
Wire.write(data);
Wire.endTransmission();
}
uint16_t BH1750FVI::getAmbientLight(void){
uint16_t ambientLightValue;
Wire.beginTransmission(i2cAddress);
Wire.requestFrom(i2cAddress, 2);
ambientLightValue = Wire.read();
ambientLightValue <<= 8;
ambientLightValue |= Wire.read();
Wire.endTransmission();
ambientLightValue = ambientLightValue/1.2; // s. page 7 of datasheet for calculation
return ambientLightValue;
}