add BH1750 sensor example
This commit is contained in:
parent
944f1b06d6
commit
a95b0c9d46
18 changed files with 1140 additions and 0 deletions
|
@ -0,0 +1,36 @@
|
|||
#include <Wire.h>
|
||||
#include <BH1750FVI.h>
|
||||
|
||||
BH1750FVI eye;
|
||||
|
||||
void setup() {
|
||||
Wire.begin();
|
||||
Serial.begin(115200);
|
||||
//setup with continuous sampling, using the low address and double sensitivity
|
||||
eye.begin(BH_ContH, BH_AddrL, 2.0);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
//test if the sensor has had time to produce a new reading
|
||||
if(eye.sampleIsFresh()){
|
||||
//read the calibration-adjusted value, according to the sensitivity setting
|
||||
word value = eye.getLightLevel('c');
|
||||
logarithmicGraphing(value);
|
||||
Serial.println(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void logarithmicGraphing(word value){
|
||||
int i=0;
|
||||
while(value>>i){
|
||||
i++;
|
||||
Serial.print(" ");
|
||||
}
|
||||
if(i>=2){
|
||||
i=i-2;
|
||||
if(value&(1<<i))Serial.print(' ');
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue