rgb led and 1 analog input?

im trying to make an rgb led light up in different colors to based on the analog input, for instance a "potentiometer" or equivelent like the lm324 controlling the input causes the input to go higher the red turns on then green and then blue progressively, i have some code worked up but am willing to work from scratch again, im working with the lm324 op-amp and an arduino w/328

Did you make this instructable?

My method of choice is to build an array of rgb values, say 255 to go the full rainbow spectrum. This is the hardest part...

then you analogread the potentiometer, and map it from 0-1024 down to 0-255, and set the rgb output pins to what the array says those values should be.

The reason I pre-build the rgb array is because there is a lot of floating point math to do the first calculations but after it's built you can just look up those values. The downside is it takes up 255*3 bytes of ram, a precious commodity in uC production.

//*******Hue to RGB functions by Frollard //*******May 2012 //*******CC NC SA //*******Converts a Hue 0-1023 to R,G,B values 0-1023 to form a looping 'rainbow' spectrum //*******Ideal to convert a pot analog input to a rainbow RGB output. //*******Does no error checking for bad input values (outside 0-1023), which should //*******never happen because numbers are sourced from the analogRead function.

analogWrite(redPin,map(redFromHue(averageHue),0,1023,0,255)); //convert the hue to red, and output analogWrite(greenPin,map(greenFromHue(averageHue),0,1023,0,255)); //convert the hue to green, and output analogWrite(bluePin,map(blueFromHue(averageHue),0,1023,0,255)); //convert the hue to blue, and output