From 5b77b28816ee8923b08abf19222be1716f656484 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Tue, 10 Aug 2021 10:20:18 +0200 Subject: added brightness curve correction this should display colors more accurately to the color on a display --- main/main.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'main') diff --git a/main/main.c b/main/main.c index 27bb6fc..ebfb8c7 100644 --- a/main/main.c +++ b/main/main.c @@ -1,4 +1,5 @@ #include +#include #include "esp_event.h" #include "esp_log.h" @@ -14,12 +15,17 @@ #include +// channel configuration #define GPIO_OUTPUT_CHANNEL_RED 0 #define GPIO_OUTPUT_CHANNEL_GREEN 0 #define GPIO_OUTPUT_CHANNEL_BLUE 2 +// pwm frequency #define PWM_PERIOD 1000 +// raises the brigtness value from 0-1 to this power +#define BRIGHTNESS_CURVE_CORRECTION 3 + static const char *TAG = "rgbstrip"; int color[3]; static httpd_handle_t server = NULL; @@ -31,9 +37,9 @@ uint32_t duties[] = {0, 0, 0}; float phase[] = {0, 0, 0}; void update_strip() { - duties[0] = PWM_PERIOD - (int)((float)(PWM_PERIOD * color[0]) / 0xff); - duties[1] = PWM_PERIOD - (int)((float)(PWM_PERIOD * color[1]) / 0xff); - duties[2] = PWM_PERIOD - (int)((float)(PWM_PERIOD * color[2]) / 0xff); + duties[0] = PWM_PERIOD - (int)( PWM_PERIOD * pow( (float)color[0] / 0xff, BRIGHTNESS_CURVE_CORRECTION ) ); + duties[1] = PWM_PERIOD - (int)( PWM_PERIOD * pow( (float)color[1] / 0xff, BRIGHTNESS_CURVE_CORRECTION ) ); + duties[2] = PWM_PERIOD - (int)( PWM_PERIOD * pow( (float)color[2] / 0xff, BRIGHTNESS_CURVE_CORRECTION ) ); pwm_set_duties(duties); pwm_start(); } -- cgit v1.2.3