add fluorescent effect foundation
This commit is contained in:
parent
49245453b4
commit
4eedd68546
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue