2016-04-22 22:26:52 +02:00
|
|
|
#include "DeviceLdr.h"
|
|
|
|
|
|
|
|
void DeviceLdr::deviceSetup() {
|
|
|
|
pinMode(pin, INPUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeviceLdr::deviceRegister() {
|
|
|
|
Homie.registerNode(ldrNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeviceLdr::deviceLoop() {
|
|
|
|
if (millis() - lastSentLDR >= INTERVAL_LDR * 1000UL || lastSentLDR == 0) {
|
|
|
|
int ldr_new = analogRead(pin);
|
|
|
|
if (ldr_new != ldr) {
|
|
|
|
ldr = ldr_new;
|
|
|
|
float ldr_float = map(ldr, 0, 1023, 0, 10000) / 100.0;
|
|
|
|
Serial.print("LDR: ");
|
|
|
|
Serial.println(ldr_float);
|
2016-04-23 01:44:56 +02:00
|
|
|
if (!Homie.setNodeProperty(ldrNode, "value", String(ldr_float), false)) {
|
2016-04-22 22:26:52 +02:00
|
|
|
Serial.println("Sending failed");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Serial.println("LDR value unchanged");
|
|
|
|
}
|
|
|
|
lastSentLDR = millis();
|
|
|
|
}
|
|
|
|
}
|