Hello,
I'm new to coding, please bear with my basic knowledge (or lack of). I've been googling for a long while.
I'd like some LEDs to change together from one specific colour to another, gradually (so they go through other colours in between), without fading to black. I'd like to have more than one transition and be able to change the duration of each one, before it loops to the beginning. I've managed to find one code, which seems to be limited to basic colours (or maybe I don't know how to tweak it to have more nuanced colours?). By specific colours I mean - for example to change from R 255, G 51, B 0 (#ff3300) to R 254, G 250, B 255 (#fefaff). I'm happy to use other colour systems but haven't managed to find a good example of how to do this with the gradual colour change. Please see the code below that works with basic colours. I also found this thread which might answer my question but the code doesn't verify on my Arduino.
LED strip WS2812b (3 pin, 5V), Arduino Uno R3.
Thank you for your time!
#include <FastLED.h>
#define DATA_PIN 4
#define NUM_LEDS 7
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
void setup(){
FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);
}
void loop(){
//start from red
for( int colorStep=0; colorStep <= 255; colorStep++ ) {
int r = 255;
int g = 0;
int b = colorStep;
// Now loop though each of the LEDs and set each one to the current color
for(int x = 0; x < NUM_LEDS; x++){
leds[x] = CRGB(r,g,b);
}
// Display the colors we just set on the actual LEDs
delay(100);
FastLED.show();
}
//into blue
for( int colorStep=255; colorStep >= 0; colorStep-- ) {
int r = colorStep;
int g = 0;
int b = 255;
// Now loop though each of the LEDs and set each one to the current color
for(int x = 0; x < NUM_LEDS; x++){
leds[x] = CRGB(r,g,b);
}
// Display the colors we just set on the actual LEDs
delay(100);
FastLED.show();
}
//start from blue
for( int colorStep=0; colorStep <= 255; colorStep++ ) {
int r = 0;
int g = colorStep;
int b = 255;
// Now loop though each of the LEDs and set each one to the current color
for(int x = 0; x < NUM_LEDS; x++){
leds[x] = CRGB(r,g,b);
}
// Display the colors we just set on the actual LEDs
delay(100);
FastLED.show();
}
//into green
for( int colorStep=255; colorStep >= 0; colorStep-- ) {
int r = 0;
int g = 255;
int b = colorStep;
// Now loop though each of the LEDs and set each one to the current color
for(int x = 0; x < NUM_LEDS; x++){
leds[x] = CRGB(r,g,b);
}
// Display the colors we just set on the actual LEDs
delay(100);
LEDS.show();
}
//start from green
for( int colorStep=0; colorStep <= 255; colorStep++ ) {
int r = colorStep;
int g = 255;
int b = 0;
// Now loop though each of the LEDs and set each one to the current color
for(int x = 0; x < NUM_LEDS; x++){
leds[x] = CRGB(r,g,b);
}
// Display the colors we just set on the actual LEDs
delay(100);
LEDS.show();
}
//into yellow
for( int colorStep=255; colorStep >= 0; colorStep-- ) {
int r = 255;
int g = colorStep;
int b = 0;
// Now loop though each of the LEDs and set each one to the current color
for(int x = 0; x < NUM_LEDS; x++){
leds[x] = CRGB(r,g,b);
}
// Display the colors we just set on the actual LEDs
delay(100);
LEDS.show();
}
}