Whole color spectrum with RGB LED using PWM

Hi, I was assigned the project of making an RGB LED circulate through the color spectrum using PWM pins and analogWrite(). How it's supposed to work is that it starts on red, and it fades into green, and green to blue, by increasing and decreasing color values. However, I have not found a good way to make this happen, and am very lost at what to do. Please help!
BTW: I am using an Arduino Romeo

For fades of a color spectrum, you might want to work in Hue, Saturation, Lightness (HSL), or Hue, Saturation, Value (HSV), then convert those values to Red, Green, Blue (RGB) for use with analogWrite(). You could then fade the entire color spectrum by varying Hue from 0 thru 360, while keeping the values of Saturation and Lightness (brightness) the same.

Best to do a Google search. You might want to find a similar project to yours which uses an Arduino RGB library. For starters, you might find this site helpful..


Good luck.

The easiest way is to write 3 for() loops, one after the other in loop(). Each for() loop runs from 0 to 255.

The first for() loop fades from red to green using analogWrite() on the red and green output pins. You want the green to fade up, so that analogWrite() is given the variable that is increased by the for() loop. You want the red to fade down, so that analogWrite() is given the value 255 - the green. Put a delay(100) in the loop to slow it down.

The second for() loop is identical to the first except that it fades the green and blue leds. The third for() loop fades the blue and red leds.