add BH1750 sensor example

This commit is contained in:
harald42 2016-05-17 16:43:11 +02:00
parent 944f1b06d6
commit a95b0c9d46
18 changed files with 1140 additions and 0 deletions

View file

@ -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(' ');
}
}