Skip to content

Commit 75daeb9

Browse files
committed
added light sensor support
1 parent 37b127b commit 75daeb9

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

include/LightSensor.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef LIGHT_SENSOR_HPP
2+
#define LIGHT_SENSOR_HPP
3+
4+
#include <BH1750FVI.h>
5+
#include <Wire.h>
6+
7+
class LightSensor {
8+
static const unsigned int CONNECTION_ATTEMPT_DELAY;
9+
BH1750FVI *lightSensor;
10+
11+
public:
12+
LightSensor(uint8_t, uint8_t);
13+
float measureLightLevel();
14+
};
15+
16+
#endif

library.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
"energia",
3131
"wiringpi"
3232
]
33+
},
34+
{
35+
"name": "BH1750FVI",
36+
"version": "1.2.4",
37+
"authors": "Enjoyneering",
38+
"frameworks": "arduino"
3339
}
3440
],
3541
"version": "0.0.1",

src/LightSensor.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "LightSensor.hpp"
2+
3+
const unsigned int LightSensor::CONNECTION_ATTEMPT_DELAY = 500;
4+
5+
LightSensor::LightSensor(uint8_t sdaPin, uint8_t sclPin) {
6+
lightSensor = new BH1750FVI(BH1750_DEFAULT_I2CADDR, BH1750_CONTINUOUS_HIGH_RES_MODE_2, BH1750_SENSITIVITY_DEFAULT, BH1750_ACCURACY_DEFAULT);
7+
8+
while (lightSensor->begin(sdaPin, sclPin) != true) {
9+
delay(CONNECTION_ATTEMPT_DELAY);
10+
Serial.print(".");
11+
}
12+
13+
Serial.println("\nBH1750FVI connected");
14+
}
15+
16+
float LightSensor::measureLightLevel() {
17+
return lightSensor->readLightLevel();
18+
}

0 commit comments

Comments
 (0)