different randomness for led strips and dim light fix

This commit is contained in:
interfisch 2018-11-23 01:49:05 +01:00
parent 94abea021a
commit 59009b630a
1 changed files with 82 additions and 17 deletions

View File

@ -33,8 +33,13 @@ long fluorescentLastActivated=0;
int fluorescentTemp=0; int fluorescentTemp=0;
#define FLUORESCENTUPDATEINTERVAL 20 #define FLUORESCENTUPDATEINTERVAL 20
long fluorescentLastUpdated=0; long fluorescentLastUpdated=0;
int fluorescentCurrentBrightness=0; //current brightness for effect duration int fluorescentCurrentBrightness0=0; //current brightness for effect duration
int fluorescentCurrentBrightness1=0;
int fluorescentCurrentBrightness2=0;
int fluorescentCurrentBrightness3=0;
#define FLUORESCENTTEMPMAX 400 #define FLUORESCENTTEMPMAX 400
int fluorescentAge=0;
#define FLUORESCENTAGEMAX 20
bool lastSensorValue = false; bool lastSensorValue = false;
@ -148,13 +153,30 @@ bool fluorescentHandler(const HomieRange& range, const String& value) {
fluorescentLastActivated=millis(); fluorescentLastActivated=millis();
fluorescentLastUpdated=millis(); fluorescentLastUpdated=millis();
fluorescentTemp=0; //"temperature" for warmup fluorescentTemp=0; //"temperature" for warmup
fluorescentCurrentBrightness=0; //brightness for effect duration fluorescentCurrentBrightness0=0; //brightness for effect duration
fluorescentCurrentBrightness1=0;
fluorescentCurrentBrightness2=0;
fluorescentCurrentBrightness3=0;
}else{
fluorescentActive=false; //set effect off
w0 = w1 = w2 = w3 = fluorescentSet;
} }
} }
output(); output();
return true; return true;
} }
bool fluorescentAgeHandler(const HomieRange& range, const String& value) {
Homie.getLogger() << "fluorescentAge " << ": " << value << endl;
fluorescentAge=value.toInt();
if (fluorescentAge<0){
fluorescentAge=0;
}else if(fluorescentAge>FLUORESCENTAGEMAX){
fluorescentAge=FLUORESCENTAGEMAX;
}
return true;
}
bool lightHandler(const HomieRange& range, const String& value) { bool lightHandler(const HomieRange& range, const String& value) {
Homie.getLogger() << "light " << ": " << value << endl; Homie.getLogger() << "light " << ": " << value << endl;
disco = false; disco = false;
@ -308,37 +330,79 @@ void loopHandler()
*/ */
fluorescentTemp+=1+ random(0,20*fluorescentTemp/FLUORESCENTTEMPMAX); int fluorescentTempIncreaseMax=61-(fluorescentAge*3);
fluorescentTemp+=1+ random(0,fluorescentTempIncreaseMax *fluorescentTemp/FLUORESCENTTEMPMAX);
//fluorescentTemp+=3; //fluorescentTemp+=3;
if (random(0,80)==0){ //ignite if (random(0,80)==0){ //ignite
fluorescentCurrentBrightness=fluorescentSet*random(50,100)/100; fluorescentCurrentBrightness0=fluorescentSet*random(50,100)/100;
fluorescentCurrentBrightness1=fluorescentSet*random(50,100)/100;
fluorescentCurrentBrightness2=fluorescentSet*random(50,100)/100;
fluorescentCurrentBrightness3=fluorescentSet*random(50,100)/100;
} }
if (fluorescentTemp>200){ // warm enough to glow if (fluorescentTemp>200){ // warm enough to glow
if (fluorescentCurrentBrightness<20){ //if under glow brightness if (fluorescentCurrentBrightness0<20){ //if under glow brightness
fluorescentCurrentBrightness+=5; //start glowing fluorescentCurrentBrightness0+=5; //start glowing
}else if(fluorescentCurrentBrightness>50){ //too bright to glow }else if(fluorescentCurrentBrightness0>50){ //too bright to glow
fluorescentCurrentBrightness-=random(0,30); //reduce intensity fluorescentCurrentBrightness0-=random(0,30); //reduce intensity
}
if (fluorescentCurrentBrightness1<20){ //if under glow brightness
fluorescentCurrentBrightness1+=5; //start glowing
}else if(fluorescentCurrentBrightness1>50){ //too bright to glow
fluorescentCurrentBrightness1-=random(0,30); //reduce intensity
}
if (fluorescentCurrentBrightness2<20){ //if under glow brightness
fluorescentCurrentBrightness2+=5; //start glowing
}else if(fluorescentCurrentBrightness2>50){ //too bright to glow
fluorescentCurrentBrightness2-=random(0,30); //reduce intensity
}
if (fluorescentCurrentBrightness3<20){ //if under glow brightness
fluorescentCurrentBrightness3+=5; //start glowing
}else if(fluorescentCurrentBrightness3>50){ //too bright to glow
fluorescentCurrentBrightness3-=random(0,30); //reduce intensity
} }
}else{ //not warm enough to glow }else{ //not warm enough to glow
if (fluorescentCurrentBrightness>0){ if (fluorescentCurrentBrightness0>0){
fluorescentCurrentBrightness-=random(20,50); //reduce intensity fluorescentCurrentBrightness0-=random(20,50); //reduce intensity
}
if (fluorescentCurrentBrightness1>0){
fluorescentCurrentBrightness1-=random(20,50); //reduce intensity
}
if (fluorescentCurrentBrightness2>0){
fluorescentCurrentBrightness2-=random(20,50); //reduce intensity
}
if (fluorescentCurrentBrightness3>0){
fluorescentCurrentBrightness3-=random(20,50); //reduce intensity
} }
} }
if (fluorescentTemp>=FLUORESCENTTEMPMAX){ //finished if (fluorescentTemp>=FLUORESCENTTEMPMAX){ //finished
fluorescentActive=false; fluorescentActive=false;
fluorescentCurrentBrightness=fluorescentSet; //set disired value fluorescentCurrentBrightness0=fluorescentSet; //set disired value
fluorescentCurrentBrightness1=fluorescentSet; //set disired value
fluorescentCurrentBrightness2=fluorescentSet; //set disired value
fluorescentCurrentBrightness3=fluorescentSet; //set disired value
} }
if (fluorescentCurrentBrightness<0){
fluorescentCurrentBrightness=0; fluorescentCurrentBrightness0=_min(255,_max(0,fluorescentCurrentBrightness0));
}else if (fluorescentCurrentBrightness>255){ fluorescentCurrentBrightness1=_min(255,_max(0,fluorescentCurrentBrightness1));
fluorescentCurrentBrightness=255; fluorescentCurrentBrightness2=_min(255,_max(0,fluorescentCurrentBrightness2));
} fluorescentCurrentBrightness3=_min(255,_max(0,fluorescentCurrentBrightness3));
w0 = w1 = w2 = w3 = fluorescentCurrentBrightness;
w0 = fluorescentCurrentBrightness0;
w1 = fluorescentCurrentBrightness1;
w2 = fluorescentCurrentBrightness2;
w3 = fluorescentCurrentBrightness3;
output(); output();
} }
} }
@ -376,6 +440,7 @@ void setup() {
lightNode.advertise("light2").settable(light2Handler); lightNode.advertise("light2").settable(light2Handler);
lightNode.advertise("light3").settable(light3Handler); lightNode.advertise("light3").settable(light3Handler);
lightNode.advertise("fluorescent").settable(fluorescentHandler); lightNode.advertise("fluorescent").settable(fluorescentHandler);
lightNode.advertise("fluorescentage").settable(fluorescentAgeHandler);
sensorNode.advertise("motion"); sensorNode.advertise("motion");