# cycling colors for RGB leds

right now I have code that cycles 3 variables for a shiftbrite project. it works but was wondering if someone had something more … “elegant”
what I want is a nice slow cycle of color in a (psudo)random manner.

here is the secton of code that does my shifting of colors right now.

``````#define Red_LED 0
#define Green_LED 1
#define Blue_LED 2

int RedUp = 1;
int GreenUp = 1;
int BlueUp = 1;
int LED;

void Shift()
{
if (LED[Red_LED] > 950) //Check if value is at the max
{ RedUp = 0; //set bit to drop value
}
else if (LED[Red_LED] < 25) //Check is Value is at the min
{ RedUp = 1; // set bit to raise value
}
if (LED[Green_LED] > 950) // repeat for each
{ GreenUp = 0;
}
else if (LED[Green_LED] < 25)
{ GreenUp = 1;
}
if (LED[Blue_LED] > 950)
{ BlueUp = 0;
}
else if (LED[Blue_LED] < 25)
{ BlueUp = 1;
}

if (RedUp == 1) //check if we should raise or lower value
{ LED[Red_LED] += 30; // raise
}
else
{ LED[Red_LED] -= 17; //lower
}
if (GreenUp == 1) //repeat
{ LED[Green_LED] += 10;
}
else
{ LED[Green_LED] -= 20;
}
if (BlueUp == 1)
{ LED[Blue_LED] += 15;
}
else
{ LED[Blue_LED] -= 5;
}
/* DEBUG:
Serial.println("...");
Serial.println(LED);
Serial.println(LED);
Serial.println(LED);
*/
}
``````

any suggestions?

TIA
–Chris

Try and think of it as a three dimensional cube. Basically what you are doing here is bouncing off the walls but always traveling at a fixed rate along an axis.
You can make that rate of change a random number.
You could generate two random points in this space and then step between these two points.
You can generate a random triplet and show it with each of the components in turn missing (that is no red, then no green, then no blue)
Finally you can explore other colour spaces like HVS colour space and bounce around in that.

Hope that gives you some ideas.

I forgot to mention that I am a total hack at programming.

You could generate two random points in this space and then step between these two points.

I like this idea,
I can figure out how to generate the “plots” but how would I get it to smoothly transition from one to another

any hints would be appreciated

on a semi related note
anyone have suggestions on waterproofing shiftbrites? I am probably going to use clear resin, but it makes the connection permanent.

There's clear silicon - can be removed, more easily than resin.

Or, put it in a ziploc bag and then just seal the bag really well.

I can figure out how to generate the "plots" but how would I get it to smoothly transition from one to another

Just treat it as lines initially in two dimensions. Take the difference bewtwwn the end points, divide that by the number of steps you want and get an increment to use to generate the points in-between. High school geometry.

Grumpy_Mike:

I can figure out how to generate the “plots” but how would I get it to smoothly transition from one to another

Just treat it as lines initially in two dimensions. Take the difference bewtwwn the end points, divide that by the number of steps you want and get an increment to use to generate the points in-between. High school geometry.

ahhhh i think i can bash that out in something that will work. will let you know if I get something close to what is in my head

figures it would be something simple that I just wouldn’t think of.

Thanks

if any others have any neat code that puts out cool color changes let me know. nothing flashy as its going on a motor vehicle… need to be noticed… not distracting.