Added Lightsensor code to project
This commit is contained in:
parent
3872b4f5fe
commit
ef8299dfbf
@ -5,8 +5,15 @@
|
|||||||
#define HEADER_H
|
#define HEADER_H
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <BH1750.h>
|
||||||
|
|
||||||
extern int meineVariable;
|
extern int meineVariable;
|
||||||
|
|
||||||
|
// moisture
|
||||||
extern void setupCapacitiveSoilMoistureSensor();
|
extern void setupCapacitiveSoilMoistureSensor();
|
||||||
extern void loopCapacitiveSoilMoistureSensor();
|
extern void loopCapacitiveSoilMoistureSensor();
|
||||||
|
|
||||||
|
// light
|
||||||
|
extern void setupLightSensor();
|
||||||
|
extern int readLightSensorValue();
|
||||||
14
src/lightSensor.cpp
Normal file
14
src/lightSensor.cpp
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#include <header.h>
|
||||||
|
|
||||||
|
BH1750 lightMeter;
|
||||||
|
|
||||||
|
void setupLightSensor() {
|
||||||
|
Wire.begin();
|
||||||
|
lightMeter.begin();
|
||||||
|
Serial.println("Sensor started...");
|
||||||
|
}
|
||||||
|
|
||||||
|
int readLightSensorValue() {
|
||||||
|
uint16_t intensity = lightMeter.readLightLevel();
|
||||||
|
return intensity;
|
||||||
|
}
|
||||||
@ -7,9 +7,15 @@
|
|||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
setupCapacitiveSoilMoistureSensor();
|
setupCapacitiveSoilMoistureSensor();
|
||||||
|
setupLightSensor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
uint16_t lxValue = readLightSensorValue();
|
||||||
|
Serial.print("Light intensity: ");
|
||||||
|
Serial.print(lxValue);
|
||||||
|
Serial.println(" lx");
|
||||||
|
|
||||||
loopCapacitiveSoilMoistureSensor();
|
loopCapacitiveSoilMoistureSensor();
|
||||||
delay(1); // delay in between reads for stability
|
delay(200); // delay in between reads for stability
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user