I’m having trouble understanding the color palletes. I have 5 10W floods I made and they work fine and the arduino controls them no problem.
My issue is that I setup a pallets where every other color alternated between purple and orange for all 16 indices. I then once a second setup every other flood to a different color (so my floods alternate between the two colors as well).
But when I run it, all the floods come up purple, then one-by-one they turn orange down the line.
What concept am I missing?
It’d help if you actually showed us the code you were using (using either http://pastebin.com or http://gist.github.com for the code).
Good point, bad move on my part… I was trying a bunch of stuff this evening, so this might not have been running exactly the way I described it, but it certainly isn’t doing the alternating like I planned/hoped: https://gist.github.com/anonymous/d6a5669597815dd963ee
Looking now (ps. remove the .js from the end of your gist – otherwise it ends up being completely unreadable)
You’re only using two color indexes, instead of actually advancing through from 0 to 255.
There in lies my stupidity. I was thinking the indices were into the 16 element color pallet…
So if I want to alternate the colors (and not be doing any of the intermediate colors), how do I go about that? I don’t see how we fill all 16 elements in the pallet, and then pick which color to use if the index is between the first and second color (0 to 255). I think somehow I am making this much too complicated in my mind.
no, for one - the 16 element palette is expanded into a 256 element palette behind the scenes, for one. For another, it’s going to do gradations between the colors, so, for example, 8 will be a mix of orange and purple.
I’m not sure a palette is really what you want to be using here.
OK, making a bit more sense, thank you for the time.
What approach would you take if I was only interested in two or three discrete colors at a time? I’ll get to fading, but that seems pretty indifferent to whatever solution is the end one.
You could just use an array of colors.
CRGB colorIndex[2];
void setup() {
…
colorIndex[0] = CRGB::Orange;
colorIndex[1] = CRGB::Purple;
…
}
void loop() {
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = colorIndex[ i % 2 ];
}
LEDS.show();
delay(1000);
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = colorIndex[ (i+1) % 2];
}
LEDS.show();
delay(1000);
}
Or, to make it a bit more arbitrary, depending on how many colors you have:
#define NUM_COLORS 4
CRGB colorIndex[NUM_COLORS];
void setup() {
….
colorIndex[0] = CRGB::Orange;
colorIndex[1] = CRGB::Purple;
colorIndex[2] = CRGB::Red;
colorIndex[3] = CRGB::Black;
…
}
void loop() {
for(int base = 0; base < NUM_COLORS; base++) {
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = colorIndex[ (i + base) % NUM_COLORS];
}
LEDS.show();
delay(1000);
}
}
Thank you for the stubs Daniel!! I’ll give them a shot tonight and report back in!
Works like a champ, thanks!