add exponential curve for pwm

This commit is contained in:
interfisch 2019-10-19 13:39:53 +02:00
parent 24361e2e12
commit e60bdf4d5d
1 changed files with 14 additions and 9 deletions

View File

@ -7,7 +7,7 @@
#define FW_NAME "tischlicht"
#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:
@ -325,8 +325,8 @@ void loopHandler() {
uint16_t pwmCW;
uint16_t pwmWW;
float temp=mapFloat(temperature, TEMPERATURE_MIN, TEMPERATURE_MAX, 0.0,1.0); //0=warmwhite, 1=coldwhite
pwmCW=(brightness*enable_fadevalue)*PWM_MAX*temp;
pwmWW=(brightness*enable_fadevalue)*PWM_MAX*(1-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=pow((brightness*enable_fadevalue)*(1-temp)/2.0, 2) *2.0 *PWM_MAX;
if (pwmCW>PWM_MAX) { pwmCW=PWM_MAX; } //limit
if (pwmWW>PWM_MAX) { pwmWW=PWM_MAX; } //limit
@ -365,6 +365,7 @@ void loopHandler() {
if (loopmillis >= last_debugupdatetime+DEBUGUPDATETIME ) {
last_debugupdatetime = loopmillis;
/*
if (!enable) { Serial.print("not enable. "); }
Serial.print("bright=");
Serial.print(brightness);
@ -378,27 +379,31 @@ void loopHandler() {
Serial.print(brightness_change_per_loop);
Serial.print(" enable_fadevalue=");
Serial.println(enable_fadevalue);
*/
/*
uint16_t pwmCW;
uint16_t pwmWW;
float temp=mapFloat(temperature, TEMPERATURE_MIN, TEMPERATURE_MAX, 0.0,1.0); //0=warmwhite, 1=coldwhite
pwmCW=brightness*PWM_MAX*temp;
pwmWW=brightness*PWM_MAX*(1-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=pow((brightness*enable_fadevalue)*(1-temp)/2.0, 2) *2.0 *PWM_MAX;
if (pwmCW>PWM_MAX) { pwmCW=PWM_MAX; } //limit
if (pwmWW>PWM_MAX) { pwmWW=PWM_MAX; } //limit
if (enable) {
Serial.print("bright=");
Serial.print(brightness);
Serial.print(PWM_MAX-pwmWW);
Serial.print(", ");
Serial.println(PWM_MAX-pwmCW);
}else{
Serial.print(0);
Serial.print("off");
Serial.print(", ");
Serial.println(0);
Serial.println("off");
}
*/
}
#endif