Hello,
I am a visual artist, and a total noob at coding. I have a WS2813 strip, with Arudino Uno for the prototype, though I may need a more powerful board for the final large piece.
I am working on a project in which I want to have a controlled fading between specific colors, and after trying out every code I could find from this board and github, and the internet at large, a nice coder helped me to modify this Fade to Color code by @marmilicious:
(His code fades beautifully, but after the one specified color, it goes into random mode.)
My code is pasted below.
If I keep all of the values (V) consistent–like at 200–then the fading across colors looks great. But the problem is that I also want a change in Values–to go from a dim aqua, up through a series of brighter sunset colors, and then back down to a dim dark blue. But if I try and adjust the Value then I get tons of flickering as the values change. Adjusting the Blend Rate does not seem to effect the smoothness. Any ideas on how to fix this?
Thanks for your help!
#include "FastLED.h"
#define DATA_PIN 8
//#define CLK_PIN 13
#define LED_TYPE WS2813
#define COLOR_ORDER GRB
#define NUM_LEDS 300
#define BRIGHTNESS 200
CRGB leds[NUM_LEDS];
uint8_t blendRate = 40; // How fast to blend. Higher is slower. [milliseconds]
//fill in your Hue, Saturation, Value (HSV) colors below. You can add or subtract additional colors as needed
CHSV color1 = CHSV(128,255,100);
CHSV color2 = CHSV(32,255,200);
CHSV color3 = CHSV(23,255,225);
CHSV color4 = CHSV(224,255,225);
CHSV color5 = CHSV(192,250,200);
CHSV color6 = CHSV(160,255,100);
//change number of colors below to reflect how many colors you have listed above
int number_of_colors = 6;
int current_color_index = 0;
//adjust he numbers below to reflect how many colors are listed above
CHSV color_array[6] = {color1, color2, color3, color4, color5, color6 };
//adjust color start CHSV and colorTarget CHSV to match colors above
CHSV colorStart = CHSV(128,255,100); // starting color
CHSV colorTarget = CHSV(160,255,100); // target color
CHSV colorCurrent = colorStart;
//---------------------------------------------------------------
void setup() {
Serial.begin(115200); // Allows serial monitor output (check baud rate)
delay(3000); // 3 second delay for recovery
//FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
Serial.println("Setup done. \n");
}
//---------------------------------------------------------------
void loop()
{
EVERY_N_MILLISECONDS(blendRate){
static uint8_t k;
if ( colorCurrent.h == colorTarget.h ) { // Check if target has been reached
colorStart = colorCurrent;
colorTarget = color_array[current_color_index]; // new target to transition toward
current_color_index += 1;
if (current_color_index == number_of_colors){
current_color_index = 0;
}
k = 0; // reset k value
Serial.print("New colorTarget:\t\t\t"); Serial.println(colorTarget.h);
}
colorCurrent = blend(colorStart, colorTarget, k, SHORTEST_HUES);
fill_solid( leds, NUM_LEDS, colorCurrent );
// leds[0] = colorTarget; // optional - set first pixel to always show target color
Serial.print("colorCurrent:\t"); Serial.print(colorCurrent.h); Serial.print("\t");
Serial.print("colorTarget:\t"); Serial.print(colorTarget.h);
Serial.print("\tk: "); Serial.println(k);
k++;
}
FastLED.show(); // update the display
}