2021-11-06 17:24:40 +00:00
|
|
|
#ifndef SENSOR_LDR_H
|
|
|
|
#define SENSOR_LDR_H
|
|
|
|
|
|
|
|
#include "sensordata.h"
|
|
|
|
#include <Homie.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Sensor_LDR
|
|
|
|
{
|
|
|
|
|
|
|
|
private:
|
|
|
|
HomieNode *sensorNode; //reference to HomieNode
|
|
|
|
|
|
|
|
int pin;
|
|
|
|
|
|
|
|
struct sensordata data; //struct values are changed in setup()
|
|
|
|
|
|
|
|
int get_lux(const unsigned int* _in, const unsigned int* _out, byte size);
|
|
|
|
|
|
|
|
//wemos d1 mini, black wire of ldr connects to A0 with 10k to gnd. red wire connects with 1k to gnd and 2k2 to 3v3
|
2021-11-07 10:00:39 +00:00
|
|
|
|
2021-11-06 18:38:54 +00:00
|
|
|
#ifdef SENSOR_LDR_CALIB_1
|
2021-11-07 10:00:39 +00:00
|
|
|
#define SENSOR_LDR_ARRAYSIZE 18
|
2021-11-06 17:24:40 +00:00
|
|
|
const unsigned int out_ldr[18] = {0, 30, 50, 60, 130, 170, 250, 420, 780, 1300,2600, 5000, 5350, 7700, 10900, 12000, 17000,20000}; // x10 (i.e. gets later divided by 10)
|
|
|
|
const unsigned int in_ldr[18] = {0, 12, 100, 150, 350, 400, 450, 650, 730, 780, 840, 930, 948 , 970, 993, 1005, 1019, 1023}; // 0 - 1023
|
2021-11-06 18:38:54 +00:00
|
|
|
#endif
|
2021-11-07 10:00:39 +00:00
|
|
|
|
2021-11-06 17:24:40 +00:00
|
|
|
bool init_ok;
|
|
|
|
public:
|
|
|
|
Sensor_LDR(int p);
|
|
|
|
|
|
|
|
|
|
|
|
void init();
|
2021-11-06 18:38:54 +00:00
|
|
|
void setSettings(float minchange, unsigned long senddelaymax, unsigned long readdelay);
|
2021-11-06 17:24:40 +00:00
|
|
|
void advertise(HomieNode& p_sensorNode);
|
|
|
|
void sensorloop();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|