aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2021-08-10 10:20:18 +0200
committerlonkaars <loek@pipeframe.xyz>2021-08-10 10:20:18 +0200
commit5b77b28816ee8923b08abf19222be1716f656484 (patch)
tree390eb82bd44a4394592f7e6f3f465e0acbd5e927
parentabf982ec977c6352f6dbf3eed6fc27f11d200836 (diff)
added brightness curve correction
this should display colors more accurately to the color on a display
-rw-r--r--main/main.c12
1 files changed, 9 insertions, 3 deletions
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 <sys/param.h>
+#include <math.h>
#include "esp_event.h"
#include "esp_log.h"
@@ -14,12 +15,17 @@
#include <esp_http_server.h>
+// 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();
}