Thanks for sharing,
I would pass the three pins to the constructor of the lib, and let m.tick do the analogWrite
furthermore you might use an ENUM for the modes.
something like
RGBmood M = new RGBMood(redpin, greenpin, bleupin);
void setup()
{
m.setMode(1); // Automatic random fade.
m.setHoldingTime(4000); // Keep the same color for 4 seconds.
m.setFadingSteps(100); // Fade with 100 steps.
m.setFadingSpeed(50); // Each step last 50ms. A complete fade takes 50*100 = 5 seconds
}
void loop()
{
// Update the colors.
m.tick();
}
m.tick()
{
// calculate new RGB values;
// existing code here....
analogWrite(_RED, _red);
analogWrite(_GREEN, _green);
analogWrite(_BLUE, _blue);
}
A fuction that could be interesting is one that calculates the distance between 2 colors
double distance(int R1, int G1, int B1, int R2, int G2, int B2)
{
return Math.sqrt((R1-R2)(R1-R2) + (G1-G2)(G1-G2) + (B1-B2) * (B1-B2));
}
with this distance function you can estimate what a still is a smooth number of steps
my 2 cents,