Hi!I'd like to be able to calculate on the fly the RGB values at any point of the color spectrum. So like by using for example a potentiometer, one can sweep the rainbow and generate RGB values. I've tried using the SIN function but would there be a way to do it without using floats to keep the code small. Can the SIN functin be used without using floats? or can someone give me a hint on how to code a simili SIN function using linear integer values (like triangle waves instead of sine waves)?

I suspect that code can be done with dot products, but if you aren't in a matrix math mood you could use a lookup table with the first quarter cycle of the sine function. That serves both sine and cosine by flopping it about different directions.

Here is one with 256 entries scaled for a byte. Don't sweat the flat spot at the end, it belongs there.

Hi Jims,Altough I'm unfamiliar with dot products and matrix math (I studied math in french, so names and techniques are little bit different at times, vive le Wikipedia!), thanks for this lookup table, I'll try it and comment on it soon. Thanks

Hmm... if you want to have the arduino look at light and analyze the rgb values, you could probably use an rgb led or individual r g and b leds and use them as light sensors. I'm not sure if this is what you mean, but I'll just throw this out there.

To me, the best way to make that is to use the HSV color mode (Hue Saturation Value)Hue = Varies from 0 to 360°. It defines the point in the spectrum, 0 = 360 = red, 10 is like a purplish color, etc... This way, you have an easy way to find all the colors in the spectrum, just by varying the angle.Saturation = "Purity" of the color. Varies from 0 to 100. The lower the value, the more the colour will be dull.Value = Brightness of the color.

Exemple : to have a pure RGB red (255,0,0), HSV value will be (360 or 0, 100,100)

You can then convert the value to RGB by using this kind of code

http://www.easyrgb.com/math.php?MATH=M21#text21

It seems that maximal value for H is 256 on this code, haven't tried it myself yet, but i gave the same advice to a guy on a french electronic forum and here's his result ^^

I was working on a HSV -> RGB function for the Arduino. In the code field below the result. It seems the work when I watch the serial output, however I didn't test it with an RGB led. This might be enough for a Rainbow ( change the hue ).

Any suggestions for improvement are welcome ( i'm more a designer than a programmer ).

I can't resist a project that makes pretty colors. I wired up an 3 potentiometer, 3 LED light and programmed it for HSV controls from the pots. I have two suggestions for improvement, one coding and one visual.

In your code you repeat a number of calculations in the switch statement with enough differences that they don't get optimized into one evaluation, I implemented them once to keep the code size down.

More importantly... Human eyes are not linear. As a very rough estimate, if you were to divide brightness up from 1 to 7, you have to double the number of photons with each step to make them look uniform. If you just run 'value' into the analog to digital converters you get a 'value' knob that is very sensitive at the low end and nearly flat at the high end.

This code addresses both of those issues. It still isn't great, the 'value' and 'saturation' knobs feel about right, but the 'hue' knob does not feel smooth. I must study color perception more deeply. It also ignores differences in brightness of the red, green, and blue LEDs, but that is ok if you handle it in the current limiting resistor.

// pgm_read_byte(x+k) is very similar to x[k] for arrays of bytes that are // stored in flash with the PROGMEM attribute analogWrite(9,pgm_read_byte( delog + r)); analogWrite(10,pgm_read_byte( delog + g)); analogWrite(11,pgm_read_byte( delog + b));