fix dimming curve for dimmable powersupply

This commit is contained in:
interfisch 2020-10-12 23:16:53 +02:00
parent 9c845af231
commit 4cc11361ea
1 changed files with 16 additions and 4 deletions

View File

@ -5,8 +5,8 @@
//Upload config: platformio run --target uploadfs //Upload config: platformio run --target uploadfs
#define TISCHLICHT //#define TISCHLICHT
//#define KUECHENLICHT #define KUECHENLICHT
#ifdef TISCHLICHT #ifdef TISCHLICHT
@ -59,6 +59,7 @@ HomieNode lightNode("light", "Light", "light"); //paramters: topic, $name, $type
#endif #endif
#ifdef KUECHENLICHT #ifdef KUECHENLICHT
#define PWM_FREQUENCY 1000 //default: 1000 Hz #define PWM_FREQUENCY 1000 //default: 1000 Hz
#define PWM_MINDIMMED PWM_MAX/3 //if light turns on later than just above 0 pwm
#endif #endif
@ -69,7 +70,13 @@ float enable_fadevalue_change_per_loop=0.01; //fixed value. For manual calculato
float set_brightness=2; //0 to 2. 1 is maximum brightness with full color range still possible. 2 is full brightness regardless of possible color temp float set_brightness=2; //0 to 2. 1 is maximum brightness with full color range still possible. 2 is full brightness regardless of possible color temp
#define BRIGHTNESS_MIN 0.0 #define BRIGHTNESS_MIN 0.0
#define BRIGHTNESS_MAX 2.0 //if temperature is in between both strips brightness of 2 means both are at full power. otherwise brightness will be clipped #define BRIGHTNESS_MAX 2.0 //if temperature is in between both strips brightness of 2 means both are at full power. otherwise brightness will be clipped
#define BRIGHTNESSCURVE 1.4 #ifdef TISCHLICHT
#define BRIGHTNESSCURVE 1.4
#endif
#ifdef KUECHENLICHT
#define BRIGHTNESSCURVE 2
#endif
float brightness=set_brightness; float brightness=set_brightness;
float brightness_change_per_loop=0; //will be calculated by Handler float brightness_change_per_loop=0; //will be calculated by Handler
@ -381,7 +388,12 @@ void loopHandler() {
analogWrite(LED_CW, PWM_MAX-pwmCW); //full pwm is led off analogWrite(LED_CW, PWM_MAX-pwmCW); //full pwm is led off
#else #else
uint16_t pwm; uint16_t pwm;
pwm=pow((brightness*enable_fadevalue)/2.0, BRIGHTNESSCURVE) *2.0 *PWM_MAX; //calculate brightness for led stripe, scale to 0-1, ^2, rescale to 0-2, scale for pwm pwm=pow((brightness*enable_fadevalue), BRIGHTNESSCURVE) *1.0 *PWM_MAX; //calculate brightness for led stripe, scale to 0-1, ^2, rescale to 0-2, scale for pwm
#ifdef PWM_MINDIMMED
if (pwm>0){ //if light should be dimmed at minimum setting
pwm=map(pwm,0,PWM_MAX,PWM_MINDIMMED,PWM_MAX); //lowest dimming setting is 0.33. rescale to fit
}
#endif
if (pwm>PWM_MAX) { pwm=PWM_MAX; } //limit if (pwm>PWM_MAX) { pwm=PWM_MAX; } //limit
analogWrite(LED_PWM, PWM_MAX-pwm); //full pwm is led off analogWrite(LED_PWM, PWM_MAX-pwm); //full pwm is led off