Merge pull request #676 from keyboardio/LEDEffect-Rainbow/fix-128-overflow

LEDEffect-Rainbow: Support more than 128 LEDs properly
pull/701/head
Jesse Vincent 5 years ago committed by GitHub
commit c17d4f81ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -63,9 +63,14 @@ void LEDRainbowWaveEffect::TransientLEDMode::update(void) {
for (auto key_addr : KeyAddr::all()) { for (auto key_addr : KeyAddr::all()) {
uint16_t key_hue = rainbow_hue + 16 * (key_addr.toInt() / 4); uint16_t key_hue = rainbow_hue + 16 * (key_addr.toInt() / 4);
if (key_hue >= 255) { // We want key_hue to be capped at 255, but we do not want to clip it to
// that, because that does not result in a nice animation. Instead, when it
// is higher than 255, we simply substract 255, and repeat that until we're
// within cap. This lays out the rainbow in a kind of wave.
while (key_hue >= 255) {
key_hue -= 255; key_hue -= 255;
} }
cRGB rainbow = hsvToRgb(key_hue, rainbow_saturation, parent_->rainbow_value); cRGB rainbow = hsvToRgb(key_hue, rainbow_saturation, parent_->rainbow_value);
::LEDControl.setCrgbAt(key_addr.toInt(), rainbow); ::LEDControl.setCrgbAt(key_addr.toInt(), rainbow);
} }

Loading…
Cancel
Save