void showRGB(int color)
{
int redIntensity;
int greenIntensity;
int blueIntensity;
if (color <= 255) // zone 1
{
redIntensity = 255 - color; // redgoes from on to off
greenIntensity = color; // green goes fromoff to on
blueIntensity = 0; // blue is always off
}
else if (color <= 511) //zone 2
{
redIntensity = 0; // red is always off
greenIntensity = 255 - (color - 256); // green on to off
blueIntensity = (color - 256); // blue off to on
}
else // color >= 512 // zone3
{
redIntensity = (color - 512); // red if off to on
greenIntensity = 0; // green is always off
blueIntensity = 255 - (color - 512); // blue off to on
}
When the value is between 0 and 255 there is an inversely correlated mix between red and green initially full red and no green to full green and no red
Then from 256 to 511 green and blue get mixed - you go from full green (so continuation of previous color) to full blue
Then from 512 to 767 you mix blue and red from full blue back to full red
This is pretty crude because human eyes do not perceive R, G or B the same way so the inverse correlation of the mix will not deliver a superbly looking rainbow spectrum.
Also make sure you wire your RGB led the right way with current limiting resistors, some colors don't have the same forward voltage but you will still send from 0 to 5V into each pin (blue and green have the same specs usually so same resistor, red Usually needs a higher resistor). Also remember the max current ability of your arduino when defining the resistor values.
The showSpectrum() function simply calls the showRGB() function with each of 768 different values, presumably to show a complete spectrum of colours using combinations of R, G and B values.
I would do the flowchart by having separate actions for initialising x (a box), incrementing x (a box) and testing x for completion (a diamond) The results of the test diamond would either lead to another action box calling showRGBxthen a delay() box then looping back to the incrementing x box, or exiting the function.