From bc34f55c1abfca72c2ab5f6e0722b56168202366 Mon Sep 17 00:00:00 2001 From: manuel Date: Wed, 1 Jan 2020 23:34:32 +0100 Subject: tv_light: fix dimming --- tv_light/src/tv_light.ino | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tv_light/src/tv_light.ino b/tv_light/src/tv_light.ino index 492069d..caf3a6e 100644 --- a/tv_light/src/tv_light.ino +++ b/tv_light/src/tv_light.ino @@ -288,6 +288,8 @@ void flipRelay(struct sensor_t *sensor, bool send_update) inline uint8_t pwmValue(uint8_t level) { + // see https://www.mikrocontroller.net/articles/LED-Fading +#if 0 static const uint8_t pwmtable[101] PROGMEM = { 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, @@ -302,6 +304,23 @@ inline uint8_t pwmValue(uint8_t level) 255 }; return (uint8_t)pgm_read_byte(&pwmtable[level]); +#else + // max pwm: 255-19, 101 steps, every step +20 + static const uint8_t pwmtable[101] PROGMEM = { + 0, 20, 20, 20, 20, 20, 20, 21, 21, 21, + 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, + 22, 22, 22, 23, 23, 23, 23, 24, 24, 24, + 24, 25, 25, 25, 26, 26, 26, 27, 27, 28, + 28, 29, 29, 30, 30, 31, 32, 32, 33, 34, + 35, 36, 37, 38, 39, 40, 41, 42, 43, 45, + 46, 48, 49, 51, 53, 55, 57, 59, 61, 63, + 66, 68, 71, 74, 77, 80, 83, 87, 91, 95, + 99, 103, 108, 113, 118, 124, 130, 136, 142, 149, + 156, 164, 172, 181, 190, 199, 209, 220, 231, 243, + 255 + }; + return 255 - (uint8_t)pgm_read_byte(&pwmtable[level]); +#endif } void fadeDimmer(struct sensor_t *sensor, uint8_t level, bool send_update) -- cgit v1.2.3