Created
December 13, 2016 06:41
-
-
Save tusing/64af8568957eb07932db00d3208bd8e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define RGBLIGHT_CURRENT_PER_STRIP_LIGHT 60 | |
#define RGBLIGHT_NUM_STRIP_LIGHTS 16 | |
#define MAX_STRIP_CURRENT 400 | |
void adjust_current(bool rgbw) { | |
// Pass in rgbw=True if you have rgbw strips. | |
float max_rgbw_val = (255 * (3 + rgbw)) * ((MAX_STRIP_CURRENT / | |
RGBLIGHT_NUM_STRIP_LIGHTS) / RGBLIGHT_CURRENT_PER_STRIP_LIGHT); | |
for (uint8_t i = 0; i < RGBLED_NUM; i++) { | |
uint8_t rgbw_total = led[i].r + led[i].g + led[i].b; | |
if (rgbw) { | |
rgbw_total += led[i].w; | |
} | |
if (rgbw_total > max_rgbw_val) { | |
float multiplier = max_rgbw_val / rgbw_total; | |
led[i].r = (uint8_t)(led[i].r * multiplier); | |
led[i].g = (uint8_t)(led[i].g * multiplier); | |
led[i].b = (uint8_t)(led[i].b * multiplier); | |
if (rgbw) { | |
led[i].w = (uint8_t)(led[i].w * multiplier) | |
} | |
} | |
} | |
} | |
void rgblight_set(void) { | |
adjust_current(false); // true if you have rgbw strips | |
// ... rest of function ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment