mirror of
https://gitee.com/peng_zhihui/HoloCubic
synced 2025-11-04 21:19:40 +08:00
39 lines
786 B
C++
39 lines
786 B
C++
#include "ambient.h"
|
|
|
|
|
|
void Ambient::init(int mode)
|
|
{
|
|
mMode = mode;
|
|
Wire.begin(AMB_I2C_SDA, AMB_I2C_SCL);
|
|
}
|
|
|
|
unsigned int Ambient::getLux()
|
|
{
|
|
Wire.beginTransmission(ADDRESS_BH1750FVI); //"notify" the matching device
|
|
Wire.write(ONE_TIME_L_RESOLUTION_MODE); //set operation mode
|
|
Wire.endTransmission();
|
|
|
|
switch (mMode)
|
|
{
|
|
case ONE_TIME_H_RESOLUTION_MODE:
|
|
delay(125);
|
|
break;
|
|
case ONE_TIME_H_RESOLUTION_MODE2:
|
|
delay(125);
|
|
break;
|
|
case ONE_TIME_L_RESOLUTION_MODE:
|
|
delay(20);
|
|
break;
|
|
}
|
|
|
|
Wire.requestFrom(ADDRESS_BH1750FVI, 2); //ask Arduino to read back 2 bytes from the sensor
|
|
highByte = Wire.read(); // get the high byte
|
|
lowByte = Wire.read(); // get the low byte
|
|
|
|
sensorOut = (highByte << 8) | lowByte;
|
|
illuminance = sensorOut / 1.2;
|
|
|
|
return illuminance;
|
|
}
|
|
|