FastLed Indicators

Hello I want to create a program on Arduino using Fasteled WB2811 led strip. My Idea is to indicate different car indicators with the leds. I know how to control every single led, but I have difficulty figuring out how to make different void loops() to change in a sequence.

Welcome to the forums. You will need to provide a bit more of a description to your problem. There is not such thing as multiple loop()s in a sketch. There can only be one function names loop(). Maybe, you create new functions, each one does whatever pattern you want? Have you looked at the FastLED examples? There are many to look at and maybe one is close to what you want.


  1. loop() is called a function.
  2. void (in this case) indicates that the function does not return a value.

Yes I saw a lot of examples but none of them help my situation. I want to create a kind of indicator dashboard for a car.So my idea is to have 3,4 functions. 1st a test: where the 12 leds light up one by one, 2nd an emergency where a some leds are blinking other don't and etc.
So in the code below I want in one loop to make all led light and after a X time to go off, and the next loop to start working where some led will only light and others will blink....

#include <FastLED.h>
#define NUM_LEDS 12
#define DATA_PIN 13
#define BRIGHTNESS  50

CRGBPalette16 currentPalette;
TBlendType    currentBlending;

extern CRGBPalette16 myRedWhiteBluePalette;
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;
    unsigned long startMillis;
    unsigned long currentMillis;
    const unsigned long period = 500;
    const byte ledPin = 13;
    int x= 0;
void setup() {
  // put your setup code here, to run once:
    FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);
    delay( 3000 ); // power-up safety delay
    FastLED.setBrightness(  BRIGHTNESS );

void loop(){
  // put your main code here, to run repeatedly:
  loop_p1(); //test
  loop_p2(); // emergency stop

void loop_p1()  {  //test
   // put your  code here
  if (currentMillis - startMillis >= period) {
    startMillis = currentMillis;
    leds[x]= CRGB:: Red;;
     leds[x]= CRGB:: Red;
    if (++x >= NUM_LEDS) x = 0;
  void loop_p1() {   //emergency 
   // put your  code here
  if (currentMillis - startMillis >= period) {
    startMillis = currentMillis;
    leds[x]= CRGB:: Red;;
     leds[x]= CRGB:: Black;
    if (++x >= NUM_LEDS) x = 0;



if you

  • rename one of the loop_p1() to loop_p2()
  • give each "sub loop" it's own "currentMillis" (either a separate global, or a static local variable in the function)

it might do what you want.

I guess it might work, but I am not that good in coding, if you have free time can you give a hand creating that..?

no that's not working this way. It's your task to code. You will get help if you ask precisely.

Does your Sketch compile?
If not why not?
What is the Compiler telling you? Read it very carefully! Still no idea?
If you can't make it working, upload your sketch AND the error message and tell how we can help.

I am asking precisely what is a seperate global or a static local variable and how to exactly implement it in my code. If you can't give me a hand because I am a newbie in coding, don't bother answering... I am hardware engeneer that's why I need help with the software...

While you wait for someone to help in the way you expect, use the time to google the terms used in describing the solution offered.

These are basic concepts in C/C++ and I dare presume every modern programming language.

global local static variable C++

might let you solve the problem; at the very least it will let you actually understand a solution if handed to you.


1 Like

Thanks I will try but in the meantime if anyone can help with other solution I will be thankful.

Look at the Blink Without Delay example in the IDE (File->examples->>Blink WIthoutDelay) and it will show you have to track elapsed time. You can do that for each of your functions.

FastLED library has already an example of how to blink withoutDelay. I already wrote the code of how I want the leds to blink or stay on. My question was and still is how to combine these code in one and run them one after a another...

int state = 0;
void loop() {
  if ( state == 0 )  function0();
  if ( state == 1 )  function1();
  if ( state == 2)  function2();
  if ( state == 3 )  function3();
void function0()
    // do your pattern here
  // check if elapsed time
  if ( millis() - startTime >= duration ) {
1 Like

Your best course of action would probably be to temporarily set the project aside and take the time to learn the fundamentals of programming in C++. The Arduino IDE contains many built-in examples. Start working your way through them. Plus, there are dozens, if not hundreds, of online tutorials.

Without doing this you'll be stuck throwing crap at the wall to see what sticks. That's hardly a structured engineering approach.

thank you so much, I will try that right away

I understand what you saying and I will take time and learn how to code. But right now I need to create this program because it is a part of my diploma and I have to show something working...

The people are here to help you practice, study and troubleshoot. If it's part of your diploma, aren't you literally asking us to do your homework for you?

On topic. You can't have separate loops run in parallel at the same time. It's just not that kind of a system. So you're going to have to simulate it. This is the bottom line of the pattern that @blh64 is suggesting.

Say your loop goes:

loop() {
  1. toggle light on/off
  2. wait 1 second
  3. go back to 1.

You could instruct the machine to simply sleep 1 second. You already got that. Easy, but this way, it blocks anything else from happening in the mean time, so doesn't work for your case.

The suggestion is then to think about it like this:

1. Remember initial timestamp T
loop() {
  2. do stuff
  3. if ("now" is more than a second after T) {
       toggle light on/off; remember current timestamp T
  4. go back to 2

For doing N things based on a time interval, you'll need N timestamps and N "schedule checks" that trigger the required action. As long as all that parallel work is not so intensive that it interferes with the schedule, you can expand it as much as you want. This way, you have functional processes that run in parallel, even though the code is linear.

I never asked you to do anything personally, you choose to help or not.. I already coded the loops which the program need to do but I don't know how to make them work one after another.. And since I am not that good in coding I asked here for help...

And since I am not that good in coding I asked here for help...

... and multiple people have offered useful insights. Which improvements or new attempts have you done after working with those insights?

Yes, I am trying to work out the thing @blh64 suggested, but having some errors so I am trying to fix them..