Fractional scrolling problem
Hi, I´m stuck and I´m not sure if it´s a construction or a implementation bug.
What do I want to do? It´s about fractional shifting of the content of a line of leds. I want to move the content without changing it. I want to be able to rotate it in a circle frame by frame for a long time.
I do it the following way: I have an leds array with the origin data. For the shifting I need to merge the data of 2 leds into the destination led.
The destination is a second CRGB array leds2 of the same size. I go through the origin array, take the 2 involved pixels and get their RGB value:
CRGB PixelA = leds[ i ];
CRGB PixelB = leds[ i + 1];
I do it only within the valid range with an extra handling for the last pixel. With integer shifting I tested it and it woks fine.
Back to the fractions: The amount of shifting is defined by a byte variable “fractions”. Based on that I scale the data:
CRGB PixelA %= fractions;
CRGB PixelB %= 255 - fractions;
The sum of these 2 I write back into the second array:
leds2[ i ] = PixelA + PixelB;
From there I copy it back into leds. (Within an extra loop.)
When calling this repeatedly I would expect the content to move slowly in one direction. After 256 calls by one pixel. And this happens, but it gets brighter while doing so. After many calls the result is just white. Somehow an error sums up and maipulates the color/saturation.
Any idea what I´m doing wrong or wrongly assume?
Thanks for any thoughts!