fluorescent effect first tries
This commit is contained in:
parent
4eedd68546
commit
87fc8d12b2
|
@ -30,6 +30,11 @@ int fluorescentSet=0;
|
||||||
bool fluorescentActive=false;
|
bool fluorescentActive=false;
|
||||||
long fluorescentLastActivated=0;
|
long fluorescentLastActivated=0;
|
||||||
#define FLUORESCENT_TIMEDIVIDE 10
|
#define FLUORESCENT_TIMEDIVIDE 10
|
||||||
|
int fluorescentTemp=0;
|
||||||
|
#define FLUORESCENTUPDATEINTERVAL 20
|
||||||
|
long fluorescentLastUpdated=0;
|
||||||
|
int fluorescentCurrentBrightness=0; //current brightness for effect duration
|
||||||
|
#define FLUORESCENTTEMPMAX 400
|
||||||
|
|
||||||
bool lastSensorValue = false;
|
bool lastSensorValue = false;
|
||||||
|
|
||||||
|
@ -130,16 +135,20 @@ bool fluorescentHandler(const HomieRange& range, const String& value) {
|
||||||
lightNode.setProperty("fluorescent").send(value);
|
lightNode.setProperty("fluorescent").send(value);
|
||||||
fluorescentSet=value.toInt();
|
fluorescentSet=value.toInt();
|
||||||
disco = false;
|
disco = false;
|
||||||
if (fluorescentSet==0){
|
if (fluorescentSet==0){ // turned off
|
||||||
fluorescentActive=false; //set effect off
|
fluorescentActive=false; //set effect off
|
||||||
w0 = 0;
|
w0 = 0;
|
||||||
w1 = 0;
|
w1 = 0;
|
||||||
w2 = 0;
|
w2 = 0;
|
||||||
w3 = 0;
|
w3 = 0;
|
||||||
}else{
|
}else{ //turned on
|
||||||
if (w0==0 && w1==0 && w2==0 && w3==0){ //turned on and was off before
|
if (w0==0 && w1==0 && w2==0 && w3==0){ //turned on and was off before
|
||||||
|
//Initialization
|
||||||
fluorescentActive=true; //start effect
|
fluorescentActive=true; //start effect
|
||||||
fluorescentLastActivated=millis();
|
fluorescentLastActivated=millis();
|
||||||
|
fluorescentLastUpdated=millis();
|
||||||
|
fluorescentTemp=0; //"temperature" for warmup
|
||||||
|
fluorescentCurrentBrightness=0; //brightness for effect duration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
output();
|
output();
|
||||||
|
@ -267,21 +276,44 @@ void loopHandler()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fluorescentActive){
|
if (fluorescentActive){
|
||||||
long _time=millis()-fluorescentLastActivated;
|
long _time=millis()-fluorescentLastActivated; //time since activated
|
||||||
int _b=_time/10;
|
|
||||||
if (_time/10>fluorescentSet){
|
|
||||||
fluorescentActive=false;
|
//mosquitto_pub -h raum.ctdo.de -t "homie/esp-deckenlicht/strip/fluorescent/set" -m "255"
|
||||||
_b=fluorescentSet; //set disired value
|
|
||||||
|
if (millis() > fluorescentLastUpdated+FLUORESCENTUPDATEINTERVAL){ //Update values
|
||||||
|
fluorescentTemp+=random(0, 5); //min (inclusive), max (exclusive)
|
||||||
|
fluorescentLastUpdated=millis();
|
||||||
|
|
||||||
|
if (random(0,256)<fluorescentTemp*1.0/FLUORESCENTTEMPMAX*256){ //the warmer, the more often
|
||||||
|
if (random(0,10)==0){ //ignite
|
||||||
|
fluorescentCurrentBrightness=fluorescentSet*0.9;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (random(0,256)>fluorescentTemp*1.0/FLUORESCENTTEMPMAX*256){ //the colder, the more often
|
||||||
|
if (fluorescentCurrentBrightness<5){ //not on
|
||||||
|
if (random(0,20)==0){ //ignite
|
||||||
|
fluorescentCurrentBrightness=fluorescentSet*0.9;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fluorescentCurrentBrightness-=50;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_b<0){
|
|
||||||
_b=0;
|
if (fluorescentTemp>=FLUORESCENTTEMPMAX){ //finished
|
||||||
}else if (_b>255){
|
fluorescentActive=false;
|
||||||
_b=255;
|
fluorescentCurrentBrightness=fluorescentSet; //set disired value
|
||||||
}
|
}
|
||||||
w0 = w1 = w2 = w3 = _b;
|
|
||||||
|
if (fluorescentCurrentBrightness<0){
|
||||||
|
fluorescentCurrentBrightness=0;
|
||||||
|
}else if (fluorescentCurrentBrightness>255){
|
||||||
|
fluorescentCurrentBrightness=255;
|
||||||
|
}
|
||||||
|
w0 = w1 = w2 = w3 = fluorescentCurrentBrightness;
|
||||||
output();
|
output();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
bool sensorValue = debouncer.read();
|
bool sensorValue = debouncer.read();
|
||||||
if (Homie.isConfigured() && Homie.isConnected() && sensorValue != lastSensorValue) {
|
if (Homie.isConfigured() && Homie.isConnected() && sensorValue != lastSensorValue) {
|
||||||
sensorNode.setProperty("motion").send(sensorValue ? "true" : "false");
|
sensorNode.setProperty("motion").send(sensorValue ? "true" : "false");
|
||||||
|
|
Loading…
Reference in New Issue