mirror of
https://gitee.com/peng_zhihui/HoloCubic
synced 2025-11-04 21:19:40 +08:00
[Fw] Fixed ambient-light filter bugs.
This commit is contained in:
parent
74dd376fdc
commit
7f2c54734f
@ -3,6 +3,7 @@
|
||||
|
||||
void Ambient::init(int mode)
|
||||
{
|
||||
mMode = mode;
|
||||
switch (mode)
|
||||
{
|
||||
case ONE_TIME_H_RESOLUTION_MODE:
|
||||
@ -17,17 +18,19 @@ void Ambient::init(int mode)
|
||||
}
|
||||
|
||||
Wire.begin(AMB_I2C_SDA, AMB_I2C_SCL);
|
||||
|
||||
delay(50);
|
||||
|
||||
Wire.beginTransmission(ADDRESS_BH1750FVI); //"notify" the matching device
|
||||
Wire.write(mMode); //set operation mode
|
||||
Wire.endTransmission();
|
||||
}
|
||||
|
||||
unsigned int Ambient::getLux()
|
||||
{
|
||||
Wire.beginTransmission(ADDRESS_BH1750FVI); //"notify" the matching device
|
||||
Wire.write(ONE_TIME_L_RESOLUTION_MODE); //set operation mode
|
||||
Wire.endTransmission();
|
||||
|
||||
if (millis() - last_time > sample_time)
|
||||
{
|
||||
|
||||
last_time = millis();
|
||||
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
|
||||
@ -37,9 +40,13 @@ unsigned int Ambient::getLux()
|
||||
|
||||
for (int i = 4; i > 0; i--) lux[i] = lux[i - 1];
|
||||
lux[0] = illuminance;
|
||||
|
||||
Wire.beginTransmission(ADDRESS_BH1750FVI); //"notify" the matching device
|
||||
Wire.write(mMode); //set operation mode
|
||||
Wire.endTransmission();
|
||||
}
|
||||
|
||||
unsigned int avg;
|
||||
unsigned int avg = 0;
|
||||
for (int i = 4; i >= 0; i--) avg += lux[i];
|
||||
avg /= 5;
|
||||
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
class Ambient
|
||||
{
|
||||
private:
|
||||
int mMode;
|
||||
unsigned char highByte = 0;
|
||||
unsigned char lowByte = 0;
|
||||
unsigned int sensorOut = 0;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user