Unwanted blink in a RGB strip led

Hello forum

I have an arduino nano and RGB strip led drived from a p9813 based RGB led driver .

I wanted the strip led to fade from one color to the other but it's happening very fast

and when I try to add a delay the blinking starts.

How can I get slowly fading without blinking ?

I uploaded the code .

Thank you all

led123.ino (777 Bytes)

#include <FastLED.h>
#define DATA_PIN 3
#define CLOCK_PIN 4
#define NUM_LEDS 50
#define LED_COUNT 256
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
int i;
int x;
int colorStep;
int c;
int m;
int n;
int p;
int r;
int g;
int b;

void setup(){
FastLED.addLeds<P9813, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);

}
void loop(){

for(c=0;c<3;c++){

for(colorStep=0;colorStep<256;colorStep++){
int m = 255-colorStep;
int n = colorStep;
int p = 0;

if(c==0){
r=m;
g=n;
b=p;

}
if(c==1){
r=p;
g=m;
b=n;

}
if(c==2){
r=n;
g=p;
b=m;

}

for(int x = 0; x < NUM_LEDS; x++){
leds[x] = CRGB(r,g,b);
}
leds*.setRGB( r, g, b);*

  • FastLED.show();*

  • }*

  • }*
    }

I would start by renaming all your variables to something meaningful. I have no idea what c stands for.

you should use a timer to change the color variables, and update the leds every time through the loop. In short, don’t use delay.

https://forum.arduino.cc/index.php?topic=503368.0

You can also look at those “blink without delay” example from the arduino ide sample sketches,

sorry about that , you are right

here it is :


#include <FastLED.h>
#define DATA_PIN 3
#define CLOCK_PIN 4
#define NUM_LEDS 50
#define LED_COUNT 256
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
int i;
int x;
int colorStep;
int shift_RGB_couple;
int m;
int n;
int p;
int r;
int g;
int b;

void setup(){
FastLED.addLeds<P9813, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);

}
void loop(){

for(shift_RGB_couple=0;shift_RGB_couple<3;shift_RGB_couple++){

for(colorStep=0;colorStep<256;colorStep++){
int m = 255-colorStep;
int n = colorStep;
int p = 0;

if(shift_RGB_couple==0){
r=m;
g=n;
b=p;

}
if(shift_RGB_couple==1){
r=p;
g=m;
b=n;

}
if(shift_RGB_couple==2){
r=n;
g=p;
b=m;

}

for(int x = 0; x < NUM_LEDS; x++){
leds[x] = CRGB(r,g,b);
}
leds*.setRGB( r, g, b);*

  • FastLED.show();*

  • }*

  • }*
    }

Qdeathstar:
I would start by renaming all your variables to something meaningful. I have no idea what c stands for.

you should use a timer to change the color variables, and update the leds every time through the loop. In short, don’t use delay.

Using millis() for timing. A beginners guide - Introductory Tutorials - Arduino Forum

You can also look at those “blink without delay” example from the arduino ide sample sketches,

Thank you for your answer , I tried using this method but unfortunately the led strip is still blinking
here is the code :


unsigned long startMillis; //some global variables available anywhere in the program
unsigned long currentMillis;
const unsigned long period = 100; //the value is a number of milliseconds
const byte ledPin = 13; //using the built in LED

#include <FastLED.h>
#define DATA_PIN 3
#define CLOCK_PIN 4
#define NUM_LEDS 50
#define LED_COUNT 256
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
int i;
int x;
int colorStep;
int shift_RGB_couple;
int m;
int n;
int p;
int r;
int g;
int b;

void setup(){
FastLED.addLeds<P9813, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);

Serial.begin(115200); //start Serial in case we need to print debugging info

startMillis = millis(); //initial start time

}
void loop(){

currentMillis = millis(); //get the current "time" (actually the number of milliseconds since the program started)

for(shift_RGB_couple=0;shift_RGB_couple<3;shift_RGB_couple++){

for(colorStep=0;colorStep<256;colorStep++){
int m = 255-colorStep;
int n = colorStep;
int p = 0;

if(shift_RGB_couple==0){
r=m;
g=n;
b=p;

}
if(shift_RGB_couple==1){
r=p;
g=m;
b=n;

}
if(shift_RGB_couple==2){
r=n;
g=p;
b=m;

}

for(int x = 0; x < NUM_LEDS; x++){
leds[x] = CRGB(r,g,b);
}
leds*.setRGB( r, g, b);*

  • if (currentMillis - startMillis >= period) //test whether the period has elapsed*

  • {*

  • FastLED.show();*

  • startMillis = currentMillis; //IMPORTANT to save the start time of the current LED state.*

  • }*

  • }*

  • }*
    }

If you must ask questions here, please learn how to do it!

OK, first things first.

You need to go and read the forum instructions so that you can go back and modify your original posts (not re-post them) - using the "More -> Modify" option below the right hand corner of your post - to mark up your code as such using the "</>" icon in the posting window. Just highlight each section of code (or output if you need to post that) from the IDE and click the icon.

In fact, the IDE has a "copy for forum" link to put these markings on a highlighted block for you so you then just paste it here in a posting window. But don't forget to use the "Auto-Format" (Ctrl-T) option first to make it easy to read. If you do not post it as "code" it can as you now see if you looked carefully, be quite garbled and is always more difficult to read.

It is inappropriate to attach it as a ".ino" file unless it is clearly too long to include in the post proper. People can usually see the mistakes directly and do not want to have to actually load it in their own IDE. And that would also assume they are using a PC and have the IDE running on that PC.

Also tidy up your blank space. Do use blank lines, but only between functional blocks.

You want to show the leds every time through the loop, but you only want to change the color of them every so often. You need to put the timer where you are changing the color of the leds, now where you are “showing” or updating the leds.

Also, does that code compile? If it doesn’t compile, you should post the error codes.

Put the program in code tags [.code] you program here [./code] without the dots.

You still have a lot of one letter variables in your sketch. You should get red of all of them. For example r to RedRGBValue or something. You want your variables enamels to be a descriptive as possible.