handler for switching LED on or off
This commit is contained in:
parent
0696e3f293
commit
96693cba64
20
things.ino
20
things.ino
@ -50,6 +50,25 @@ void setupHandler() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ledOnHandler(String value) {
|
||||||
|
if (value == "true") {
|
||||||
|
analogWrite(PIN_LED_RED, led_red);
|
||||||
|
analogWrite(PIN_LED_GREEN, led_green);
|
||||||
|
analogWrite(PIN_LED_BLUE, led_blue);
|
||||||
|
Homie.setNodeProperty(ledNode, "on", "true");
|
||||||
|
Serial.println("led is on");
|
||||||
|
} else if (value == "false") {
|
||||||
|
analogWrite(PIN_LED_RED, 0);
|
||||||
|
analogWrite(PIN_LED_GREEN, 0);
|
||||||
|
analogWrite(PIN_LED_BLUE, 0);
|
||||||
|
Homie.setNodeProperty(ledNode, "on", "false");
|
||||||
|
Serial.println("led is off");
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool ledColorHandler(String message) {
|
bool ledColorHandler(String message) {
|
||||||
DynamicJsonBuffer json_inBuffer;
|
DynamicJsonBuffer json_inBuffer;
|
||||||
JsonObject& json_in = json_inBuffer.parseObject(message);
|
JsonObject& json_in = json_inBuffer.parseObject(message);
|
||||||
@ -170,6 +189,7 @@ void setup() {
|
|||||||
Homie.registerNode(ldrNode);
|
Homie.registerNode(ldrNode);
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAS_LED
|
#ifdef HAS_LED
|
||||||
|
ledNode.subscribe("on", ledOnHandler);
|
||||||
ledNode.subscribe("color", ledColorHandler);
|
ledNode.subscribe("color", ledColorHandler);
|
||||||
Homie.registerNode(ledNode);
|
Homie.registerNode(ledNode);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user