Hi, I'm pretty new to arduino and I'm currently trying to make a crossfading RGB LED.
I've written some code but wasn't really happy with it because it was always locked in a while-loop so i looked up and stumbled upon this: http://arduino.cc/en/Tutorial/ColorCrossfader

I read through the code and understood most of it but there is one thing I don't really get:

``````* In the real program, the color percentages are converted to
* 0-255 values, and there are 1020 steps (255*4).
*
* To figure out how big a step there should be between one up- or
* down-tick of one of the LED values, we call calculateStep(),
* which calculates the absolute gap between the start and end values,
* and then divides that gap by 1020 to determine the size of the stepĀ
* between adjustments in the value.
``````

Why does he multiply the 255 with 4? I don't really see, why he chose this? Why can't I simply not take 1000 steps? Of course, the crossfading would be a bit faster, but still...

Can someone explain this to me, please?

Why does he multiply the 255 with 4? I don't really see, why he chose this? Why can't I simply not take 1000 steps

Because in that way the steps match and have an even effect. If he were to use 1000 steps then there would not be a physical change consistently every 4 steps.

So he increased the resolution of steps from 255 per color to 1020?

katofl:
So he increased the resolution of steps from 255 per color to 1020?

Not for real but for the purpose of doing calculations on the numbers. In this way he could keep to using integers in place of floating point numbers. This is because using integers is so much faster. The actual PWM resolution is still only 8 bits.