Can I make one more animation help request for my mermaid tail?

Can I make one more animation help request for my mermaid tail?

I am doing a photo shoot tonight, and for still photos, I want a still gradient pattern that uses variables (thishue, thissat, etc) so I can change the colors from a still blue-to-purple gradient to, say, a green-to-yellow gradient or a red-to-orange gradient. (I’ve got a bluetooth controller working where I can change the variables on the fly).

I’ve got a nice gradient going here but I don’t know how to work in the variables (thishue, thissat) since it’s spelled out in RGB… any pointers?

void gradient() { // Still Gradient
int N9 = int(LED_COUNT/17);
for (int i = 0; i < LED_COUNT; i++ ) {
if (i >= 0 && i < N9) {leds[i].r = 0; leds[i].g = 0; leds[i].b = 255;}
if (i >= N9 && i < N92) {leds[i].r = 20; leds[i].g = 0; leds[i].b = 255;}
if (i >= N9
2 && i < N93) {leds[i].r = 40; leds[i].g = 0; leds[i].b = 255;}
if (i >= N9
3 && i < N94) {leds[i].r = 60; leds[i].g = 0; leds[i].b = 255;}
if (i >= N9
4 && i < N95) {leds[i].r = 80; leds[i].g = 0; leds[i].b = 255;}
if (i >= N9
5 && i < N96) {leds[i].r = 100; leds[i].g = 0; leds[i].b = 255;}
if (i >= N9
6 && i < N97) {leds[i].r = 120; leds[i].g = 0; leds[i].b = 255;}
if (i >= N9
7 && i < N98) {leds[i].r = 140; leds[i].g = 0; leds[i].b = 255;}
if (i >= N9
8 && i < LED_COUNT) {leds[i].r = 160; leds[i].g = 0; leds[i].b = 255;}
}
LEDS.show();
delay(100);
}

Thanks!!
-Erin

If you want to convert it to use CHSV() you can. You’ll have to understand how the colors get mapped on the HSV wheel (http://en.wikipedia.org/wiki/HSL_and_HSV), for example hue = 0 (or 360) is red, hue = 120 is green, hue = 240 is blue. In between those values you get color mixing.

However, since you already have it in CRGB() mode, why not stick with that? Have a case switch that you control (via BT). A (very) simple (static) method is this:

void gradient(uint8_t colorGradient) { // Still Gradient
int N9 = int(LED_COUNT/17);
for (int i = 0; i < LED_COUNT; i++ ) {
if (i >= 0 && i < N9) {
switch (colorGradient) {
case 0: leds[i] = CRGB(0, 0, 255); break; // blue-mag
case 1: leds[i] = CRGB(255, 0, 0); break; // red-mag
case 2: leds[i] = CRGB(0, 255, 0); break; // green-yel
}
}

  if (i >= N9 && i < N9*2)   {
    switch (colorGradient) {
      case 0: leds[i] = CRGB(40, 0, 255); break;  // blue-mag
      case 1: leds[i] = CRGB(255, 0, 40); break;  // red-mag
      case 2: leds[i] = CRGB(40, 255, 0); break;  // green-yel
    }
  }
}

}
}

Note I said static method because you are setting the colors individually, as opposed to doing it mathematically. There are different ways of skinning the cat here.

If I’m not missing something, I think it should be as easy as replacing

{leds[i].r = 0; leds[i].g = 0; leds[i].b = 255;}

with

{leds[i].setHSV(thishue, thissat, val;}

Also, you might want to consider getting rid of the blocking delay() so you don’t miss serial input from the BT.

I’m taking a line from your code:
leds[i].r = 160; leds[i].g = 0; leds[i].b = 255;
You can write this in your code to make it easier to read:
leds[i] = CRGB(160, 0, 255 )
Now to switch everything to hsv, it needs to have this format:
leds[i] = CHSV(hue, saturation, value)
leds[i] = CHSV(160,255,255)

To create your gradient in HSV, you will need to alter the combination of saturation and value. The lower the saturation, the more white you will see in the hue. The lower the value, the more dim the color will be. Here are the first 3 lines of your code augmented with HSV:

if (i >= 0 && i < N9)      {leds[i] = CHSV(160,255,255);} 
if (i >= N9 && i < N9*2)   {leds[i] = CHSV(165,255, 255);}     
if (i >= N9*2 && i < N9*3) {leds[i] = CHSV(170, 255,255);} 

To make the variables easy to change, try this:

byte hue = 160;
byte saturation = 255;
byte value = 255;

void gradient(){
if (i >= 0 && i < N9) {leds[i] = CHSV(hue, saturation, value);}
if (i >= N9 && i < N92) {leds[i] = CHSV(hue + 5, saturation, value);}
if (i >= N9
2 && i < N9*3) {leds[i] = CHSV(hue + 10, saturation, value);}
}

And yes, my way will make for a rather large block of repeating code (and it’s not how I would do it), but I’m trying not to completely break things and/or confuse you.

If you do want to go the CHSV() route, I would strongly suggest you calculate the values mathematically, as opposed to setting them fixed. You’ll get a much better transition that way too.

If you want to go from 240 (blue) to magenta (roughly 330), you can use those as lower and upper bounds and “ping-pong” between them.

incr = 10;
hue = 240;

leds[i] = CHSV(hue, 255, 255);

hue += incr; // increase hue by a value of 10 with each loop
if ((hue > 330) || (hue < 240)) { // upper/lower bounds
incr = !incr;
}

You can also calculate which pixel you’re working with and get rid of the if statements that checks each one individually.

Hey @Erin_St_Blaine , how did the photo shoot go?

Pretty awesome. I must program a Sunset mode now… one of my favorite photos accidentally captured the bit of rainbow-swirl that matches the sky perfectly. I suspect I’ll do a lot of photo shoots at sunset, so might as well be ready. :slight_smile: Here are a few of my faves. We got some video too but I haven’t edited it yet. First swim is tomorrow!

missing/deleted image from Google+

Those are awesome! You’re right, you’re going to create a “sunset” mode now. :slight_smile: