From 4eedd68546e4ec387f56ce705c5805c348f3b004 Mon Sep 17 00:00:00 2001 From: Fisch Date: Fri, 16 Nov 2018 00:06:58 +0100 Subject: [PATCH] add fluorescent effect foundation --- esp-deckenlicht.ino | 46 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/esp-deckenlicht.ino b/esp-deckenlicht.ino index 4a45e73..2d01aa4 100644 --- a/esp-deckenlicht.ino +++ b/esp-deckenlicht.ino @@ -25,6 +25,12 @@ int strobo = 1; bool disco = false; int lastEvent = 0; +//Fluorescent effect +int fluorescentSet=0; +bool fluorescentActive=false; +long fluorescentLastActivated=0; +#define FLUORESCENT_TIMEDIVIDE 10 + bool lastSensorValue = false; HomieNode lightNode("strip", "strip"); @@ -118,6 +124,28 @@ bool discoHandler(const HomieRange& range, const String& value) { return true; } + +bool fluorescentHandler(const HomieRange& range, const String& value) { + Homie.getLogger() << "fluorescent " << ": " << value << endl; + lightNode.setProperty("fluorescent").send(value); + fluorescentSet=value.toInt(); + disco = false; + if (fluorescentSet==0){ + fluorescentActive=false; //set effect off + w0 = 0; + w1 = 0; + w2 = 0; + w3 = 0; + }else{ + if (w0==0 && w1==0 && w2==0 && w3==0){ //turned on and was off before + fluorescentActive=true; //start effect + fluorescentLastActivated=millis(); + } + } + output(); + return true; +} + bool lightHandler(const HomieRange& range, const String& value) { Homie.getLogger() << "light " << ": " << value << endl; disco = false; @@ -238,6 +266,22 @@ void loopHandler() step++; } } + if (fluorescentActive){ + long _time=millis()-fluorescentLastActivated; + int _b=_time/10; + if (_time/10>fluorescentSet){ + fluorescentActive=false; + _b=fluorescentSet; //set disired value + } + + if (_b<0){ + _b=0; + }else if (_b>255){ + _b=255; + } + w0 = w1 = w2 = w3 = _b; + output(); + } bool sensorValue = debouncer.read(); if (Homie.isConfigured() && Homie.isConnected() && sensorValue != lastSensorValue) { sensorNode.setProperty("motion").send(sensorValue ? "true" : "false"); @@ -271,6 +315,7 @@ void setup() { lightNode.advertise("light1").settable(light1Handler); lightNode.advertise("light2").settable(light2Handler); lightNode.advertise("light3").settable(light3Handler); + lightNode.advertise("fluorescent").settable(fluorescentHandler); sensorNode.advertise("motion"); @@ -291,4 +336,3 @@ void loop() { debouncer.update(); ArduinoOTA.handle(); } -