mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
71 lines
1.3 KiB
C++
71 lines
1.3 KiB
C++
//
|
|
// FILE: BH1750FVI_async.ino
|
|
// AUTHOR: Rob Tillaart
|
|
// VERSION: 0.1.0
|
|
// PURPOSE: demo of BH1750FVI lux scanner library
|
|
// DATE: 2020-08-20
|
|
//
|
|
|
|
|
|
#include "BH1750FVI.h"
|
|
|
|
BH1750FVI myLux(0x23);
|
|
|
|
float correctionFactor = 0.45; // min value see datasheet
|
|
uint32_t count = 0;
|
|
|
|
|
|
void setup()
|
|
{
|
|
Serial.begin(115200);
|
|
Serial.println();
|
|
Serial.print(__FILE__);
|
|
Serial.println();
|
|
|
|
Wire.begin();
|
|
|
|
myLux.powerOn();
|
|
myLux.setContHighRes();
|
|
}
|
|
|
|
|
|
void loop()
|
|
{
|
|
if (myLux.isReady())
|
|
{
|
|
float val = myLux.getLux();
|
|
|
|
if (count % 20 == 0)
|
|
{
|
|
Serial.println("\nCNT \tLUX \tMODE \tFACTOR \tRAWLUX");
|
|
}
|
|
|
|
Serial.print(count);
|
|
Serial.print("\t");
|
|
Serial.print(val, 1);
|
|
Serial.print("\t");
|
|
Serial.print(myLux.getMode());
|
|
Serial.print("\t");
|
|
Serial.print(myLux.getCorrectionFactor(), 2);
|
|
Serial.print("\t");
|
|
Serial.println(val / myLux.getCorrectionFactor(), 1);
|
|
|
|
// note correction factor are steps of 1/69 internally, see datasheet
|
|
correctionFactor += 0.05;
|
|
if (correctionFactor > 3.68) // 0.45 - 3.68 = 45 steps of 0.05
|
|
{
|
|
correctionFactor = 0.45;
|
|
Serial.println();
|
|
}
|
|
myLux.setCorrectionFactor(correctionFactor); // 0.45 .. 3.68
|
|
|
|
count++;
|
|
}
|
|
delay(1000);
|
|
// do other things here
|
|
}
|
|
|
|
|
|
// -- END OF FILE --
|
|
|