From 4cc11361ea0cd1e447de5cdbc40cf5995dc17890 Mon Sep 17 00:00:00 2001 From: Fisch Date: Mon, 12 Oct 2020 23:16:53 +0200 Subject: [PATCH] fix dimming curve for dimmable powersupply --- src/main.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1465a33..b5aded2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,8 +5,8 @@ //Upload config: platformio run --target uploadfs -#define TISCHLICHT -//#define KUECHENLICHT +//#define TISCHLICHT +#define KUECHENLICHT #ifdef TISCHLICHT @@ -59,6 +59,7 @@ HomieNode lightNode("light", "Light", "light"); //paramters: topic, $name, $type #endif #ifdef KUECHENLICHT #define PWM_FREQUENCY 1000 //default: 1000 Hz + #define PWM_MINDIMMED PWM_MAX/3 //if light turns on later than just above 0 pwm #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 #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 BRIGHTNESSCURVE 1.4 +#ifdef TISCHLICHT + #define BRIGHTNESSCURVE 1.4 +#endif +#ifdef KUECHENLICHT + #define BRIGHTNESSCURVE 2 +#endif + float brightness=set_brightness; 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 #else 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 analogWrite(LED_PWM, PWM_MAX-pwm); //full pwm is led off