add exponential curve for pwm
This commit is contained in:
parent
24361e2e12
commit
e60bdf4d5d
|
@ -7,7 +7,7 @@
|
||||||
#define FW_NAME "tischlicht"
|
#define FW_NAME "tischlicht"
|
||||||
#define FW_VERSION "1.0.3"
|
#define FW_VERSION "1.0.3"
|
||||||
|
|
||||||
//#define DEBUG //turns on continuous serial debug printing
|
#define DEBUG //turns on continuous serial debug printing
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* To Update configuration (wifi credentials) from data/homie/config.json:
|
* To Update configuration (wifi credentials) from data/homie/config.json:
|
||||||
|
@ -325,8 +325,8 @@ void loopHandler() {
|
||||||
uint16_t pwmCW;
|
uint16_t pwmCW;
|
||||||
uint16_t pwmWW;
|
uint16_t pwmWW;
|
||||||
float temp=mapFloat(temperature, TEMPERATURE_MIN, TEMPERATURE_MAX, 0.0,1.0); //0=warmwhite, 1=coldwhite
|
float temp=mapFloat(temperature, TEMPERATURE_MIN, TEMPERATURE_MAX, 0.0,1.0); //0=warmwhite, 1=coldwhite
|
||||||
pwmCW=(brightness*enable_fadevalue)*PWM_MAX*temp;
|
pwmCW=pow((brightness*enable_fadevalue)*temp/2.0, 2) *2.0 *PWM_MAX; //calculate brightness for led stripe, scale to 0-1, ^2, rescale to 0-2, scale for pwm
|
||||||
pwmWW=(brightness*enable_fadevalue)*PWM_MAX*(1-temp);
|
pwmWW=pow((brightness*enable_fadevalue)*(1-temp)/2.0, 2) *2.0 *PWM_MAX;
|
||||||
|
|
||||||
if (pwmCW>PWM_MAX) { pwmCW=PWM_MAX; } //limit
|
if (pwmCW>PWM_MAX) { pwmCW=PWM_MAX; } //limit
|
||||||
if (pwmWW>PWM_MAX) { pwmWW=PWM_MAX; } //limit
|
if (pwmWW>PWM_MAX) { pwmWW=PWM_MAX; } //limit
|
||||||
|
@ -365,6 +365,7 @@ void loopHandler() {
|
||||||
if (loopmillis >= last_debugupdatetime+DEBUGUPDATETIME ) {
|
if (loopmillis >= last_debugupdatetime+DEBUGUPDATETIME ) {
|
||||||
last_debugupdatetime = loopmillis;
|
last_debugupdatetime = loopmillis;
|
||||||
|
|
||||||
|
/*
|
||||||
if (!enable) { Serial.print("not enable. "); }
|
if (!enable) { Serial.print("not enable. "); }
|
||||||
Serial.print("bright=");
|
Serial.print("bright=");
|
||||||
Serial.print(brightness);
|
Serial.print(brightness);
|
||||||
|
@ -378,27 +379,31 @@ void loopHandler() {
|
||||||
Serial.print(brightness_change_per_loop);
|
Serial.print(brightness_change_per_loop);
|
||||||
Serial.print(" enable_fadevalue=");
|
Serial.print(" enable_fadevalue=");
|
||||||
Serial.println(enable_fadevalue);
|
Serial.println(enable_fadevalue);
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
uint16_t pwmCW;
|
uint16_t pwmCW;
|
||||||
uint16_t pwmWW;
|
uint16_t pwmWW;
|
||||||
float temp=mapFloat(temperature, TEMPERATURE_MIN, TEMPERATURE_MAX, 0.0,1.0); //0=warmwhite, 1=coldwhite
|
float temp=mapFloat(temperature, TEMPERATURE_MIN, TEMPERATURE_MAX, 0.0,1.0); //0=warmwhite, 1=coldwhite
|
||||||
pwmCW=brightness*PWM_MAX*temp;
|
pwmCW=pow((brightness*enable_fadevalue)*temp/2.0, 2) *2.0 *PWM_MAX; //calculate brightness for led stripe, scale to 0-1, ^2, rescale to 0-2, scale for pwm
|
||||||
pwmWW=brightness*PWM_MAX*(1-temp);
|
pwmWW=pow((brightness*enable_fadevalue)*(1-temp)/2.0, 2) *2.0 *PWM_MAX;
|
||||||
|
|
||||||
if (pwmCW>PWM_MAX) { pwmCW=PWM_MAX; } //limit
|
if (pwmCW>PWM_MAX) { pwmCW=PWM_MAX; } //limit
|
||||||
if (pwmWW>PWM_MAX) { pwmWW=PWM_MAX; } //limit
|
if (pwmWW>PWM_MAX) { pwmWW=PWM_MAX; } //limit
|
||||||
|
|
||||||
if (enable) {
|
if (enable) {
|
||||||
|
Serial.print("bright=");
|
||||||
|
Serial.print(brightness);
|
||||||
Serial.print(PWM_MAX-pwmWW);
|
Serial.print(PWM_MAX-pwmWW);
|
||||||
Serial.print(", ");
|
Serial.print(", ");
|
||||||
Serial.println(PWM_MAX-pwmCW);
|
Serial.println(PWM_MAX-pwmCW);
|
||||||
}else{
|
}else{
|
||||||
Serial.print(0);
|
Serial.print("off");
|
||||||
Serial.print(", ");
|
Serial.print(", ");
|
||||||
Serial.println(0);
|
Serial.println("off");
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue