Skip to content

Instantly share code, notes, and snippets.

@tusing
Created December 13, 2016 06:41
Show Gist options
  • Save tusing/64af8568957eb07932db00d3208bd8e8 to your computer and use it in GitHub Desktop.
Save tusing/64af8568957eb07932db00d3208bd8e8 to your computer and use it in GitHub Desktop.
#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