0

I'm creating a wordclock and I'd like to change the ws2812b led strip color slowly, so that it fades from one colour to another. However, I'm new to arduino and I can't get it done and I also could not find anything on this anywhere (probably because of using the wrong keywords)

Currently I have a colour hardcoded like this:

void SwitchLED(int MyArray[], int n) {
     for (i = MyArray[0]; i < MyArray[0]+n; i++) {
          leds[i].setRGB((161,57,0); 
     }
}

(The array in this code are the LEDs that will light up depending on the time I get from a ds3231).

So I would like a (random) starting colour to slowly change to another colour and so on. This in such a way that you will notice it only after a couple of minutes, so very slow and subtle.

I'm using the FastLED libary. I bit of help on this would be appreciated very much.

2
  • Something like leds[i].setHSV(millis()/1000, 255, 255);?
    – gre_gor
    Feb 14 '17 at 2:40
  • That's great, exactly what I needed. Thank you.
    – itsme86
    Feb 15 '17 at 17:48
0

For the color, you can use the time (millis()) as a hue parameter.

void SwitchLED(int MyArray[], int n) {
    CRGB color = CHSV(millis()/1024, 255, 255);
    for (i = MyArray[0]; i < MyArray[0]+n; i++) {
        leds[i] = color; 
    }
}

I used 1024 here to scale the time, so it takes 4 min 22 sec, to go through the hue cycle. And a power of two, should solve a visual glitch on millis() overflow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.