Added Lightsensor code to project

This commit is contained in:
Sebastian 2020-06-23 11:48:42 +02:00
parent 3872b4f5fe
commit ef8299dfbf
3 changed files with 29 additions and 2 deletions

View File

@ -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
View 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;
}

View File

@ -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
} }