Arduino Forum

Using Arduino => LEDs and Multiplexing => Topic started by: DSGFlash on Oct 26, 2018, 08:40 pm

Title: Dynamic turn signals stop and parking lights - WS2812b
Post by: DSGFlash on Oct 26, 2018, 08:40 pm
Hi guys  :)
I have question for you. I want to make lighting for my motorcycle trunk.
I have a WS2812b led strip (8 led per page) and Arduino pro mini. I tried to write something myself but the problem is that I do not know the arduino programming environment ( and I can not write code for controlling such lighting. Can any of you help me write such a code?
I apologize if I wrote this topic in the wrong part.

Greetings.
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: AWOL on Oct 26, 2018, 09:27 pm
Quote
I tried to write something myself
So, post that.
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: DSGFlash on Oct 27, 2018, 12:55 pm
I wrote something like that. These are dynamic directions. I do not know how to do the rest, i.e. parking lights and braking, and how to do it using the voltage from the motorcycle.
Can anyone help me to write this code to control these LEDs?

Thank you
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: Paul__B on Oct 27, 2018, 02:00 pm
Can anyone help me to write this code to control these LEDs?
No, but I will help you to show your code:
Code: [Select]
#include <FastLED.h>

#define LED_PIN     2
#define NUM_LEDS    16

CRGB leds[NUM_LEDS];

void setup() {
  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
  
}

void loop() {

  leds[7] = CRGB(255,255,0);
  FastLED.show();
  delay(60);
  leds[6] = CRGB(255,255,0);
  FastLED.show();
  delay(60);
  leds[5] = CRGB(255,255,0);
  FastLED.show();
  delay(60);
  leds[4] = CRGB(255,255,0);
  FastLED.show();
  delay(60);
  leds[3] = CRGB(255,255,0);
  FastLED.show();
  delay(60);
  leds[2] = CRGB(255,255,0);
  FastLED.show();
  delay(60);
  leds[1] = CRGB(255,255,0);
  FastLED.show();
  delay(60);
  leds[0] = CRGB(255,255,0);
  FastLED.show();
  delay(70);               // left turn signal

FastLED.clear(); {

}
 leds[8] = CRGB(255,255,0);
  FastLED.show();
  delay(60);
  leds[9] = CRGB(255,255,0);
  FastLED.show();
  delay(60);
  leds[10] = CRGB(255,255,0);
  FastLED.show();
  delay(60);
  leds[11] = CRGB(255,255,0);
  FastLED.show();
  delay(60);
  leds[12] = CRGB(255,255,0);
  FastLED.show();
  delay(60);
  leds[13] = CRGB(255,255,0);
  FastLED.show();
  delay(60);
  leds[14] = CRGB(255,255,0);
  FastLED.show();
  delay(60);
  leds[15] = CRGB(255,255,0);
  FastLED.show();
  delay(70);             // right turn signal

FastLED.clear();
}
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: lesept on Oct 27, 2018, 06:15 pm
I can help you with the code because I like the project, but:
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: lesept on Oct 27, 2018, 10:11 pm
Here is a first version

Code: [Select]
#include <FastLED.h>

#define LED_PIN1     2
#define NUM_LEDS1    16

// buttons for commands
#define StopButton 3
#define ClignoButton 4
#define PosButton 5

CRGB leds[NUM_LEDS];

byte NCligno = 0;
bool Cligno = false;
bool Stop = false;
bool Position = true;
const byte BrightnessPos = 40; // %
const byte BrightnessCligno = 100;
const byte BrightnessStop = 100;

unsigned long ClignoDur = 100ul;
unsigned long Chrono = 0;

void ReadButtons () {
    Cligno = !digitalRead(ClignoButton);
    Stop = !digitalRead(StopButton);
    Position = !digitalRead(PosButton);
    delay(25);
}

void LightCligno (byte n) {
  int orange = 255*BrightnessCligno/100;
  for (int i=0;i<n;i++) leds[i] = CRGB(orange,orange,0);
}

void LightAll (byte b) {
  int red = 255*b/100;
  for (int i=0;i<NUM_LEDS1;i++) leds[i] = CRGB(red,0,0);
}

void setup() {
  FastLED.addLeds<WS2812B, LED_PIN1, GRB>(leds, NUM_LEDS1);
  pinMode (StopButton,INPUT_PULLUP);
  pinMode (ClignoButton,INPUT_PULLUP);
  pinMode (PosButton,INPUT_PULLUP);
  Serial.begin(115200);
  Chrono = millis();
}

void loop() {
  ReadButtons ();
   
  if (!Position) {
    FastLED.clear();
  } else LightAll (BrightnessPos);
 
  if (Stop) LightAll (BrightnessStop);
   
  else if (Cligno) {
    if (millis()-Chrono>ClignoDur) {
      Chrono = millis();
      NCligno = (NCligno+1)%NUM_LEDS1;
      LightCligno (NCligno);
    }
  }
 
  FastLED.show();
}


It only addresses one led strip of 16 leds, for only one side. When it works, we'll work on the version for two led strips.

It assumes 3 buttons, which are actually pushbuttons. One for the dim red lights (I called it position, as in French) connected between pin 5 and GND. One for the stop light, connected between pin 3 and GND. The last one for turn signal, between pin 4 and GND (called cligno for clignotant).

If no button is pushed, all the leds are off.
If the stop button is pushed, whatever the status of the other buttons, all the leds are on, red with high brightness.
If only the position button is pushed, all the leds are red but with lower brightness. Brightness values can be modified, from 0 to 100.
If the turn button is pushed, the leds lit one after the other, hopefully orange, with high brightness. If the position button is also pushed, the remaining leds are red with lower brightness.

Test it, and tell me what you see...
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: DSGFlash on Oct 27, 2018, 11:56 pm
It is exactly as you wrote. Lights stop and position lights, work well. In turn direction lights, I changed the value of "unsigned long ClignoDur to value = 0ul, because at the value of 100ul LEDs was flashing. At this point in the code you need to add 1 because Arduino throws an error: CRGB leds[NUM_LEDS1]; Regarding the directions lights, it would be necessary to synchronize them with those that I have in a motorcycle. That they ignite and off at the same moment. The direction light function now works in the loop. It seems to me that this loop would have to be removed. Therefore, that after each time a mass pulse is given, the left or right direction would perform only one full cycle of the dynamic direction. Then it will be easier to synchronize with them the direction indicator that I have in the motorcycle. And the ability to adjust the "swimming" speed of the dynamic direction indicators for the right and left turn signals. I hope you know what I mean. You also have to divide them into the left and right side after 8 led. Regarding the control I will try to make a transistor-based circuit or use relays.
@lesept Thank you for your help :)
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: lesept on Oct 28, 2018, 09:48 am
Hi
I'm more comfortable with code than with electronics, so I can only help on the code part. I don't know how to synchronize the turn lights with what you call the impulse of the mass. Maybe someone else in this forum understands better than me what it is and how to wire the arduino to catch that signal.

I supposed in my code that you would be testing with pushbuttons but in the real implementation, I think that the commands will be from switches, except for the stop light. In this case, the delay line should be removed from the code, and you should use a capacitance to cancel the possible bounces at the stop button. You'll find lots of information about this on the internet.

Then, the value of ClignoDur should be set to a non zero value, and this value will help synchronize the wave and your existing turn light.
This will need to be set by trial and error, unless you can precisely measure the period of your existing turn signal.

I'll provide a new version with the 2 directions, you ll need another button or switch, one for turning left and one for turning right. I mean for testing purpose, but for the real implementation, you'll have to tell me how you get the control signals from your bike.

Do you also need a 'warning' signal, as we call it in French, ie both turn waves synchronized? If yes, this will require another button or switch to command it.
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: DSGFlash on Oct 28, 2018, 09:58 am
The direction light function now works in the loop. It seems to me that this loop would have to be removed. Therefore, that after each time a mass pulse is given, the left or right direction would perform only one full cycle of the dynamic direction. Then it will be easier to synchronize with them the direction indicator that I have in the motorcycle. And the ability to adjust the "swimming" speed of the dynamic direction indicators for the right and left turn signals. All signals from the motorcycle are controlled using 12v. Mass control for arduino can stay I will try to make a circuit using transistor or relays.  Warning lights (emergency) you do not have to do this this can be done using the left and right turn signal.
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: lesept on Oct 28, 2018, 10:38 am
What you call "mass signal" must be a parasitic signal that I would translate as "a call for current" from the light bulb when it's switched on (but my knowledge in electronics is quite low so there may be another explanation). I don't think it can be fed directly to a pin of the arduino. You should catch it with another circuit which will provide a 'correct" signal to the Arduino.

Now, for the code: do you have switches?

If yes, I can change the code accordingly. If you can put a switch for left / right direction, and add a pushbutton that would simulate that "mass signal", I can rewrite the code to manage that. There, we need to decide when to stop the wave, maybe with another push on this pushbutton for the moment.

Similarly, you can put ON/OFF switches for position and stop lights, although I don't think the code needs any change for those.
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: lesept on Oct 28, 2018, 11:07 am
Here is the new version :
Code: [Select]
#include <FastLED.h>

#define LED_PIN1     2
#define NUM_LEDS1    16

// buttons for commands (all connected between pin and GND)
#define StopButton 3
#define ClignoSwitch 4
#define PosSwitch 5
#define MassSignal 6

CRGB leds[NUM_LEDS1]; // 0-7 left, 8-15 right

byte NCligno = 0;
bool Cligno = false; // received mass signal ?
bool ClignoState = false; // turn light on or off ?
bool ClignoDir = false; // true : right, false : left
bool Stop = false;
bool Position = true;
const byte BrightnessPos = 40; // %
const byte BrightnessCligno = 100;
const byte BrightnessStop = 100;

unsigned long ClignoDur = 10ul;
unsigned long Chrono = 0;

void ReadButtons () {
  ClignoDir = digitalRead(ClignoSwitch); // put a ! if not the correct direction
  Cligno = !digitalRead(MassSignal);
  Stop = !digitalRead(StopButton);
  Position = !digitalRead(PosSwitch);
  delay(20); // To be removed eventually
  if (Cligno) ClignoState = !ClignoState;
}

void LightCligno (byte n, bool Direction) {
  byte Offset = (Direction) ? 8 : 0;
  int orange = 255 * BrightnessCligno / 100;
  for (int i = 0; i < n; i++) leds[i + Offset] = CRGB(orange, orange, 0);
}

void LightAll (byte b) {
  int red = 255 * b / 100;
  for (int i = 0; i < NUM_LEDS1; i++) leds[i] = CRGB(red, 0, 0);
}

void setup() {
  FastLED.addLeds<WS2812B, LED_PIN1, GRB>(leds, NUM_LEDS1);
  pinMode (StopButton, INPUT_PULLUP);
  pinMode (ClignoSwitch, INPUT_PULLUP);
  pinMode (PosSwitch, INPUT_PULLUP);
  pinMode (MassSignal, INPUT_PULLUP);
  Serial.begin(115200);
  Chrono = millis();
}

void loop() {
  ReadButtons ();

  if (!Position) {
    FastLED.clear(); // Position light OFF
  } else LightAll (BrightnessPos); // Position light ON

  if (Stop) LightAll (BrightnessStop); // Stop light ON

  else if (ClignoState) {
    if (millis() - Chrono > ClignoDur) {
      Chrono = millis();
      NCligno = (NCligno + 1) % (NUM_LEDS1 / 2);
      LightCligno (NCligno, ClignoDir);
    }
  }

  FastLED.show();
}

So you need switches (or pushbuttons and you keep them pushed to simulate the switches) for turn and position lights, and pushbuttons for stop and mass signals. The strip is divided in 2 parts (left and right) and hopefully the lit part will depend on the direction switch... They begin to flash when the mass button is pushed and stop when it is pushed again.

Try it and tell me how it works...
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: DSGFlash on Oct 28, 2018, 12:18 pm
Works only the right-hand direction on pin 6, on pin 4 not works, the left-hand direction. This direction still works in the loop. The wave works on 7 diodes and should be on 8. The diodes from 8 to 14 are on. Diode 15 should also light up (diodes count from 0 like Arduino).
The left turn signal works when the right turn signal is on and gives the mass on pin 4. It also lights up in a wave of 7 LEDs, from: 0 to: 6, LED 7 should also light up and the wave should work the other way from diode: 7 to diode: 0. The mass impulse be given at the frequency with which the blinkers of the motorcycle flash. So it must work on the principle that after giving the mass the direction must perform one full cycle of the wave and after the next mass application it must again make a full wave cycle and so on over and over when the mass impulse is applied. If we used the mass to stop the wave then the direction would flash every other cycle.
Yes I have switches I do it on the contact board. Can the disappearance of the mass pulse cause the wave to stop? What I mean is that arduino gets a mass pulse from the motorcycle turn signal on the input, lights the wave (one cycle, no loop), the mass impulse from the motorcycle disappears and then the wave is stopped and so on and on? I know it is easier to do in the loop but then it will be harder to synchronize the direction indicators with each other.

Position lights and brake lights work well and you do not have to change anything in the code for them.
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: lesept on Oct 28, 2018, 01:36 pm
Quote
Works only the right-hand direction on pin 6, on pin 4 not works, the left-hand direction.
Actually, all the leds are connected to pin 2. Pin 6 is connected to the switch: please refer here  (http://forum.arduino.cc/index.php?topic=11540.0)to see how to connect the switch.

Here is a new version with turn signal going up and down.
Code: [Select]
#include <FastLED.h>

#define LED_PIN1     2
#define NUM_LEDS1    16

// buttons for commands (all connected between pin and GND)
#define StopButton 3
#define ClignoSwitch 4
#define PosSwitch 5
#define MassSignal 6

CRGB leds[NUM_LEDS1]; // 0-7 left, 8-15 right

byte NCligno = 0;
bool Cligno = false; // received mass signal ?
bool ClignoState = false; // turn light on or off ?
bool ClignoDir = false; // true : right, false : left
bool ClignoUp = true; // true : lights from 0 to 7, false : the other way
bool Stop = false;
bool Position = true;
const byte BrightnessPos = 40; // %
const byte BrightnessCligno = 100;
const byte BrightnessStop = 100;

unsigned long ClignoDur = 10ul;
unsigned long Chrono = 0;

void ReadButtons () {
  ClignoDir = digitalRead(ClignoSwitch); // put a ! if not the correct direction
  Cligno = !digitalRead(MassSignal);
  Stop = !digitalRead(StopButton);
  Position = !digitalRead(PosSwitch);
  delay(20); // To be removed eventually
  if (Cligno) ClignoState = !ClignoState;
}

void LightCligno (byte n, bool Direction) {
  byte Offset = (Direction) ? 8 : 0;
  int orange = 255 * BrightnessCligno / 100;
  for (int i = 0; i < n; i++) leds[i + Offset] = CRGB(orange, orange, 0);
  if (!ClignoUp && !Position) leds[n] = CRGB(0, 0, 0);
  if (!ClignoUp &&  Position) {
    int red = 255 * BrightnessPos / 100;
    leds[n] = CRGB(red, 0, 0);
  }
}

void LightAll (byte b) {
  int red = 255 * b / 100;
  fill_solid(leds, NUM_LEDS1, CRGB(red, 0, 0));
  //  for (int i = 0; i < NUM_LEDS1; i++) leds[i] = CRGB(red, 0, 0);
}

void setup() {
  FastLED.addLeds<WS2812B, LED_PIN1, GRB>(leds, NUM_LEDS1);
  pinMode (StopButton, INPUT_PULLUP);
  pinMode (ClignoSwitch, INPUT_PULLUP);
  pinMode (PosSwitch, INPUT_PULLUP);
  pinMode (MassSignal, INPUT_PULLUP);
  Serial.begin(115200);
  Chrono = millis();
}

void loop() {
  ReadButtons ();

  if (!Position) {
    FastLED.clear(); // Position light OFF
  } else LightAll (BrightnessPos); // Position light ON

  if (Stop) LightAll (BrightnessStop); // Stop light ON

  else if (ClignoState) {
    if (millis() - Chrono > ClignoDur) {
      Chrono = millis();
      LightCligno (NCligno, ClignoDir);
      if (ClignoUp) {
        NCligno += 1;
        if (NCligno == NUM_LEDS1 / 2) ClignoUp = !ClignoUp;
      }
      else {
        NCligno -= 1;
        if (NCligno == 0) ClignoUp = !ClignoUp;
      }
    }
  }

  FastLED.show();
}
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: DSGFlash on Oct 28, 2018, 02:50 pm
I understand only pinn number 4, it is not possible to turn on the direction. Only with pin 6, and pin 4 switches to the other direction indicator. This must work independently that pin 6 can be used to turn the right turn signal on and off. By contrast, the pin 4 must also work independently to turn the left turn signal on and off. In this code, it is not possible to turn on the left blinker with pin 4. You must turn on the right turn signal with pin 6 and then hold the mass on pin 4 then the left direction works. Now the wave works after 8 LEDs per side as it should, but there is another wave effect. I sent you a movie on PM as there is now a wave effect and how it should be. Can you change the lighting order of the left turn signal wave? Now the wave of the left direction starts from diode 0 to diode 7, if you can change it on starts from diode 7 and ends with diode: 0. Thank you very much for your help, you helped me a lot and I'm sorry that I am still asking for help, but I can not do it myself.
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: lesept on Oct 28, 2018, 04:31 pm
No worries, I said I'd help you and I'm glad to do it. I'll watch the videos, which one does show the effect you want?

I don't understand what you mean here:
Quote
I understand only pin number 4, it is not possible to turn on the direction. Only with pin 6, and pin 4 switches to the other direction indicator. This must work independently that pin 6 can be used to turn the right turn signal on and off. By contrast, the pin 4 must also work independently to turn the left turn signal on and off. In this code, it is not possible to turn on the left blinker with pin 4. You must turn on the right turn signal with pin 6 and then hold the mass on pin 4 then the left direction works.
Pin 4 should be connected to a switch. This device provides either LOW or HIGH to pin 4, depending on the direction it points to. Did you read how to connect the switch in the URL I recommended? So depending on the value the pin receives, the left turn or the right turn signal is shown. At least, this is what I tried to code :)

Then, pin 6 is connected to the so-called mass signal. For now, it launches the wave and another push stops it.
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: DSGFlash on Oct 28, 2018, 07:09 pm
A movie called: "It must be so.mp4" shows the desired effect. At the same time, the diodes from the range from 0 to: 7 must light up in the reverse order, that is from the diode: 7 to the diode: 0. Exactly this code works as you wrote.
I sent you a movie in PM how the work looks like, see if it works correctly.
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: lesept on Oct 28, 2018, 07:52 pm
Thanks for the video, it's nice to see it working. I think you should slow it down by increasing the value of ClignoDur
So, is this ok for you as it is ?
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: DSGFlash on Oct 28, 2018, 08:10 pm
I will manage the change in speed.
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: lesept on Oct 28, 2018, 11:21 pm
Ok, please explain again what you need, I didn't understand your answer #15...
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: lesept on Oct 29, 2018, 08:58 am
Hi
I understood this morning that the 'mass signal' must be used for the synchronization of the turn signal (the wave, up and down), so I'll send you another version taking this into account. The mass signal will launch only one wave (up and down) on the side given by the direction switch.

I had an idea, tell me what you think. For now, if you have the sign turn on and if you brake, the sign turn disappears and you only see the brake lights as long as you push the stop button. But I can add a reminder of the turn sign while the stop lights are lit: instead of the wave, I can lit only one led, going up and down.

It's not a complex modification, what do you think about it?
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: lesept on Oct 29, 2018, 10:04 am
New version, including the idea I told you about:
Code: [Select]
#include <FastLED.h>
#define LED_PIN1     2
#define NUM_LEDS1   16

// buttons / switches for commands
#define StopButton 3
#define TurnSwitch 4
#define PosSwitch  5
#define MassSignal 6

CRGB leds[NUM_LEDS1]; // 0-7 left, 8-15 right

byte NTurn = 0;
bool Mass      = false;  // received mass signal ?
bool MassOld   = false;  // previous value
bool TurnState = false;  // turn light on or off ?
bool TurnDir   = false;  // true : right, false : left
bool TurnUp    = true;   // true : lights from 0 to 7, false : the other way
bool Stop      = false;  // stop light on or off ?
bool Position  = true;   // position light on or off ?

const byte BrightnessPos  =  40; // percentage
const byte BrightnessTurn = 100;
const byte BrightnessStop = 100;

unsigned long TurnDur     = 30ul;
unsigned long Chrono      = 0;

void ReadButtons () {
  TurnDir  =  digitalRead(TurnSwitch); // put a ! if not the correct direction
  Stop     = !digitalRead(StopButton);
  Position = !digitalRead(PosSwitch);
  MassOld  = Mass;
  Mass     = true; //!digitalRead(MassSignal);
  delay(20); // for debouncing AND filtering mass signal

  // Detection of the rising edge of the mass signal
  if (Mass && !MassOld) TurnState = true;
}

void LightTurn (byte n, bool Direction) {
  byte Offset = (Direction) ? 8 : 0;
  int orange  = 255 * BrightnessTurn / 100;
  int red     = 255 * BrightnessPos / 100;
  if (Stop) leds[n + Offset] = CRGB(orange, orange, 0);
  else {
    for (int i = 0; i < n; i++) leds[i + Offset] = CRGB(orange, orange, 0);
    if (!TurnUp) leds[n + Offset] = CRGB(red * Position, 0, 0);
  }
}

void TurnSignal () {
  if (millis() - Chrono > TurnDur) {
    Chrono = millis();
    Serial.println(NTurn);
    LightTurn (NTurn, TurnDir);
    if (TurnUp) {
      NTurn += 1;
      if (NTurn == NUM_LEDS1 / 2) TurnUp = !TurnUp;
    } else {
      NTurn -= 1;
      if (NTurn == 0) TurnState = false;
    }
  }
}

void LightAll (byte Bright) {
  int red = 255 * Bright / 100;
  fill_solid(leds, NUM_LEDS1, CRGB(red, 0, 0));
}

void setup() {
  FastLED.addLeds<WS2812B, LED_PIN1, GRB>(leds, NUM_LEDS1);
  pinMode (StopButton, INPUT_PULLUP);
  pinMode (TurnSwitch, INPUT_PULLUP);
  pinMode (PosSwitch,  INPUT_PULLUP);
  pinMode (MassSignal, INPUT_PULLUP);
  Serial.begin(115200);
  Serial.println("HELLO");
  Chrono = millis();
}

void loop() {
  ReadButtons ();

  if (!Position) {
    FastLED.clear(); // Position light OFF
  } else LightAll (BrightnessPos);     // Position light ON

  if (Stop) LightAll (BrightnessStop); // Stop light ON
  if (TurnState) TurnSignal ();        // Do the wave

  FastLED.show();
}

Now, if everything goes right, the turn signal is launched only when you hit the mass button
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: DSGFlash on Oct 29, 2018, 10:45 am
Code from post #12 shows the effect, wave on the movie: "this effect is.mp4" which I sent you. I want the effect for wave that is shown in the movie: "It must be so.mp4". The left wave starts working, from the diode: 0 to the diode: 7. It is the left direction so its work must start from the diode: 7 to the diode: 0 (change it, as you can). Otherwise, I have to cut the left led strip and turn it 180 degrees. The right wave is ok because it is the right direction indicator and the work starts from the diode: 8 to the diode: 15 and so it has to stay.
Is it possible that after each mass application on the pin that corresponds to the direction indicator control, the wave performed one full cycle and stopped? After re-applying the mass again will complete the full wave cycle and stop again? Yes over and over again when the mass is served. The point is that the wave frac after the mass application always must start starts with the first diode in the ruler for the left and right direction indicators. Now when I give the mass, the wave starts in a random place, it should always start work after giving the mass, from the first diode in the 8led strip (because the whole bar is divided into 2 parts of 8 LEDs). In practice, it has to work in this way (right turn signal). I give the mass and keep on pin 6 the wave performs one full cycle starting from the diode: 8 to: 15 and stops. I detach the mass from the pin 6 the wave goes out. Gives the mass again and I keep on pin 6, the wave performs one full cycle from the diode: 8 to the diode: 15. I detach the mass from the pin 6 the wave goes out. For the left turn signal the same way. I give the mass on pin 4 and I keep, the wave starts working now from the diode: 7 to the diode: 0 performs one full cycle and stops. I detach the mass from the pin 4 the wave goes out. Again I give the mass on the pin 4 wave starts working from the diode: 7 to diode: 0, performs one full cycle, stops. I detach the mass from the pin 4 the wave goes out. I hope you understood me. When giving the mass on pin 4, I need to be able to turn the wave on and off (now there is no such possibility). Now I have to turn on the mass wave on pin 6 and I can turn on the wave (left turn signal) by putting the mass on pin 4. You can make the turn signal lights work when the brake lights are on. The code from post # 20 does not work correctly. Gives the mass on the pin 6 wave will make one full cycle and go out. Later the braking and parking lights do not work anymore when I give the mass. It's still not the wave effect that I want. At the beginning of this post I wrote you which effect is to be. Thank you for your help and I'm sorry I'm still asking for it.
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: lesept on Oct 29, 2018, 11:32 am
Here is another version:
Code: [Select]
#include <FastLED.h>
#define LED_PIN1     2
#define NUM_LEDS1   16

// buttons / switches for commands
#define StopButton 3
#define TurnSwitch 4
#define PosSwitch  5
#define MassSignal 6

CRGB leds[NUM_LEDS1]; // 0-7 left, 8-15 right

byte NTurn = 0;
bool Mass      = false;  // received mass signal ?
bool MassOld   = false;  // previous value
bool TurnState = false;  // turn light on or off ?
bool TurnDir   = false;  // true : right, false : left
bool TurnUp    = true;   // true : lights from 0 to 7, false : the other way
bool Stop      = false;  // stop light on or off ?
bool Position  = true;   // position light on or off ?

const byte BrightnessPos  =  40; // percentage
const byte BrightnessTurn = 100;
const byte BrightnessStop = 100;

unsigned long TurnDur     = 30ul;
unsigned long Chrono      = 0;

void ReadButtons () {
  TurnDir  =  digitalRead(TurnSwitch); // put a ! if not the correct direction
  Stop     = !digitalRead(StopButton);
  Position = !digitalRead(PosSwitch);
  MassOld  = Mass;
  Mass     = !digitalRead(MassSignal);
  delay(20); // for debouncing AND filtering mass signal

  // Detection of the rising edge of the mass signal
  if (Mass && !MassOld) TurnState = true;
}

void LightTurn (byte n, bool Direction) {
  byte Offset = (Direction) ? 8 : 0;
  int orange  = 255 * BrightnessTurn / 100;
  int red     = 255 * BrightnessPos  / 100;
  byte kn = n * Direction + (7 - n) * (1 - Direction);
  if (Stop) leds[kn + Offset] = CRGB(orange, orange, 0);
  else {
    for (int i = 0; i < n; i++) {
      byte k = i * Direction + (7 - i) * (1 - Direction);
      leds[k + Offset] = CRGB(orange, orange, 0);
    }
    if (!TurnUp) leds[kn + Offset] = CRGB(red * Position, 0, 0);
  }
}

void TurnSignal () {
  if (millis() - Chrono > TurnDur) {
    Chrono = millis();
    LightTurn (NTurn, TurnDir);
    if (TurnUp) {
      NTurn += 1;
      if (NTurn == NUM_LEDS1 / 2) TurnUp = !TurnUp;
    } else {
      NTurn -= 1;
      if (NTurn == 0) TurnState = false;
    }
  }
}

void LightAll (byte Bright) {
  int red = 255 * Bright / 100;
  fill_solid(leds, NUM_LEDS1, CRGB(red, 0, 0));
}

void setup() {
  FastLED.addLeds<WS2812B, LED_PIN1, GRB>(leds, NUM_LEDS1);
  pinMode (StopButton, INPUT_PULLUP);
  pinMode (TurnSwitch, INPUT_PULLUP);
  pinMode (PosSwitch,  INPUT_PULLUP);
  pinMode (MassSignal, INPUT_PULLUP);
  Serial.begin(115200);
  Chrono = millis();
}

void loop() {
  ReadButtons ();

  if (!Position) {
    FastLED.clear(); // Position light OFF
  } else LightAll (BrightnessPos);     // Position light ON

  if (Stop) LightAll (BrightnessStop); // Stop light ON
  if (TurnState) TurnSignal ();        // Do the wave

  FastLED.show();
}
The only change is I try to have the wave go from 7 down to 0 and then up for the left sign.

Quote
Is it possible that after each mass application on the pin that corresponds to the direction indicator control, the wave performed one full cycle and stopped?
That's what I tried to do. The problem is that I can't test it here, so I'm "blind coding". You need to explain precisely what you see to help me understand what I have to change.
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: lesept on Oct 29, 2018, 11:43 am
Quote
In practice, it has to work in this way (right turn signal). I give the mass and keep on pin 6 the wave performs one full cycle starting from the diode: 8 to: 15 and stops. I detach the mass from the pin 6 the wave goes out.
OK I see, it's not what I thought.

So what you want for the right turn signal is:
And the same for the left sign:
Is this correct ?

I'll work on that shortly.
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: lesept on Oct 29, 2018, 12:24 pm
Here is what I did:
Code: [Select]
#include <FastLED.h>
#define LED_PIN1     2
#define NUM_LEDS1   16

// buttons / switches for commands
#define StopButton  3
#define LeftSignal  4
#define PosSwitch   5
#define RightSignal 6

CRGB leds[NUM_LEDS1]; // 0-7 left, 8-15 right

byte NTurnLeft  = 8;
byte NTurnRight = 7;
bool TurnLeft   = false;  //
bool WasLeft    = false;  // previous value for left light
bool TurnRight  = false;  //
bool WasRight   = false;  // previous value for roght light
bool Stop       = false;  // stop light on or off ?
bool Position   = true;   // position light on or off ?

const byte BrightnessPos  =  40; // percentage
const byte BrightnessTurn = 100;
const byte BrightnessStop = 100;

unsigned long TurnDur     = 30ul;
unsigned long Chrono      = 0;

void ReadButtons () {
  TurnLeft  = digitalRead(LeftSignal);
  TurnRight = digitalRead(RightSignal);
  Stop      = !digitalRead(StopButton);
  Position  = !digitalRead(PosSwitch);
  delay(20); // for debouncing
}

void TurnSignalRightUp () {
  if (millis() - Chrono > TurnDur) {
    Chrono = millis();
    int orange  = 255 * BrightnessTurn / 100;
    for (int i = NUM_LEDS1 / 2; i < NTurnRight; i++) leds[i] = CRGB(orange, orange, 0);
    NTurnRight ++;
    if (NTurnRight > NUM_LEDS1) {
      NTurnRight = NUM_LEDS1;
      WasRight = true;
    }
  }
}

void TurnSignalRightDown () {
  if (millis() - Chrono > TurnDur) {
    Chrono = millis();
    int orange  = 255 * BrightnessTurn / 100;
    for (int i = NUM_LEDS1 / 2; i < NTurnRight; i++) leds[i] = CRGB(orange, orange, 0);
    NTurnRight --;
    if (NTurnRight < NUM_LEDS1 / 2) {
      NTurnRight = NUM_LEDS1 / 2;
      WasRight = false;
    }
  }
}

void TurnSignalLeftUp () {
  if (millis() - Chrono > TurnDur) {
    Chrono = millis();
    int orange  = 255 * BrightnessTurn / 100;
    for (int i = 0; i < NTurnLeft; i++) leds[i] = CRGB(orange, orange, 0);
    NTurnLeft ++;
    if (NTurnLeft > NUM_LEDS1 / 2) {
      NTurnLeft = NUM_LEDS1 / 2;
      WasLeft = true;
    }
  }
}

void TurnSignalLeftDown () {
  if (millis() - Chrono > TurnDur) {
    Chrono = millis();
    int orange  = 255 * BrightnessTurn / 100;
    for (int i = 0; i < NTurnLeft; i++) leds[i] = CRGB(orange, orange, 0);
    NTurnLeft --;
    if (NTurnLeft < 0) {
      NTurnLeft = 0;
      WasLeft = false;
    }
  }
}

void LightAll (byte Bright) {
  int red = 255 * Bright / 100;
  fill_solid(leds, NUM_LEDS1, CRGB(red, 0, 0));
}

void setup() {
  FastLED.addLeds<WS2812B, LED_PIN1, GRB>(leds, NUM_LEDS1);
  pinMode (StopButton,  INPUT_PULLUP);
  pinMode (LeftSignal,  INPUT_PULLUP);
  pinMode (PosSwitch,   INPUT_PULLUP);
  pinMode (RightSignal, INPUT_PULLUP);
  Serial.begin(115200);
  Chrono = millis();
}

void loop() {
  ReadButtons ();

  if (!Position) {
    FastLED.clear();               // Position light OFF
  } else LightAll (BrightnessPos); // Position light ON

  if (Stop) LightAll (BrightnessStop);    // Stop light ON

  if (!TurnRight) TurnSignalRightUp ();   // Do the right wave up
  if (TurnRight && WasRight) TurnSignalRightDown ();   // Do the right wave down

  if (!TurnLeft) TurnSignalLeftDown ();   // Do the left wave down
  if (TurnLeft && WasLeft) TurnSignalLeftUp ();   // Do the left wave up

  FastLED.show();
}
Hope it does what you want...
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: DSGFlash on Oct 29, 2018, 01:31 pm
The code from post # 24 it works in 99% good, you have to correct only a few things that I described below. Controlling pinen 6 works very well but after removing the mass, the yellow LEDs must go out completely (not one after the other). Now they go out one by one. For pin number 4 you have to do the same (exactly the same and the same mass control as for pin 6) only LEDs are to light up from the diode: 7 to diode: 0
If you correct it then it will be everything I wanted :)
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: lesept on Oct 29, 2018, 01:55 pm
Thanks
You mean that all the left or right leds must be set off at the same time, not one after the other?

Just remove these 2 lines:

Code: [Select]
  if (TurnRight && WasRight) TurnSignalRightDown ();   // Do the right wave down


...


  if (TurnLeft && WasLeft) TurnSignalLeftUp ();   // Do the left wave up
I think it'll do it. If it's ok, I'll provide an updated version, with the stop light AND the turn lights
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: DSGFlash on Oct 29, 2018, 02:02 pm
For lamps, the left or right direction indicators must be turned off at the same time, not one after the other.
See it looks like:
https://www.youtube.com/watch?v=HPLX1_EP1HY

I removed the line:
if (TurnRight && WasRight) TurnSignalRightDown ();   // Do the right wave down

if (TurnLeft && WasLeft) TurnSignalLeftUp ();   // Do the left wave up

The LEDs then ignite completely and go out completely. So that is not what I want.

In the code below, I changed the values to ++ and now the right turn signal works as it should. But it goes out only after 2 seconds from subtracting the mass from pin 6, and it should go off immediately. So you have to correct it or do it in a different way.


Quote
void TurnSignalRightDown () {
  if (millis() - Chrono > TurnDur) {
    Chrono = millis();
    int orange  = 255 * BrightnessTurn / 100;
    for (int i = NUM_LEDS1 / 2; i < NTurnRight; i++) leds = CRGB(orange, orange, 0);
    NTurnRight ++;                 //I changed to ++
    if (NTurnRight < NUM_LEDS1 / 2) {
      NTurnRight = NUM_LEDS1 / 2;
      WasRight = false;
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: lesept on Oct 29, 2018, 03:16 pm
How about this?

Code: [Select]
#include <FastLED.h>
#define LED_PIN1     2
#define NUM_LEDS1   16

// buttons / switches for commands
#define StopButton  3
#define LeftSignal  4
#define PosSwitch   5
#define RightSignal 6

CRGB leds[NUM_LEDS1]; // 0-7 left, 8-15 right

byte NTurnLeft  = 8;
byte NTurnRight = 7;
bool TurnLeft   = false;  //
bool TurnRight  = false;  //
bool Stop       = false;  // stop light on or off ?
bool Position   = true;   // position light on or off ?

const byte BrightnessPos  =  40; // percentage
const byte BrightnessTurn = 100;
const byte BrightnessStop = 100;

unsigned long TurnDur     = 30ul;
unsigned long Chrono      = 0;

void ReadButtons () {
  TurnLeft  = digitalRead(LeftSignal);
  TurnRight = digitalRead(RightSignal);
  Stop      = !digitalRead(StopButton);
  Position  = !digitalRead(PosSwitch);
  delay(20); // for debouncing
}

void TurnSignalRightUp () {
  if (millis() - Chrono > TurnDur) {
    Chrono = millis();
    int orange  = 255 * BrightnessTurn / 100;
    for (int i = NUM_LEDS1 / 2; i < NTurnRight; i++) leds[i] = CRGB(orange, orange, 0);
    NTurnRight ++;
    if (NTurnRight > NUM_LEDS1) {
      NTurnRight = NUM_LEDS1;
      TurnRight = true;
    }
  }
}

void TurnSignalLeftDown () {
  if (millis() - Chrono > TurnDur) {
    Chrono = millis();
    int orange  = 255 * BrightnessTurn / 100;
    for (int i = 0; i < NTurnLeft; i++) leds[i] = CRGB(orange, orange, 0);
    NTurnLeft --;
    if (NTurnLeft < 0) {
      NTurnLeft = 0;
      TurnLeft = true;
    }
  }
}

void LightAll (byte Bright) {
  int red = 255 * Bright / 100;
  fill_solid(leds, NUM_LEDS1, CRGB(red, 0, 0));
}

void setup() {
  FastLED.addLeds<WS2812B, LED_PIN1, GRB>(leds, NUM_LEDS1);
  pinMode (StopButton,  INPUT_PULLUP);
  pinMode (LeftSignal,  INPUT_PULLUP);
  pinMode (PosSwitch,   INPUT_PULLUP);
  pinMode (RightSignal, INPUT_PULLUP);
  Serial.begin(115200);
  Chrono = millis();
}

void loop() {
  ReadButtons ();

  if (!Position) {
    FastLED.clear();               // Position light OFF
  } else LightAll (BrightnessPos); // Position light ON

  if (Stop) LightAll (BrightnessStop);    // Stop light ON

  if (!TurnRight) TurnSignalRightUp ();   // Do the right wave up
  if (!TurnLeft) TurnSignalLeftDown ();   // Do the left wave down

  FastLED.show();
}
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: DSGFlash on Oct 29, 2018, 03:54 pm
How about this?
The wave works well the first time. Behind the next one, it lights up and goes out completely. Unless I touch pin 4 and then pin 6 then it works well once. See I sent you a video on PM.
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: lesept on Oct 29, 2018, 04:33 pm
Try with this:

Code: [Select]
#include <FastLED.h>
#define LED_PIN1     2
#define NUM_LEDS1   16

// buttons / switches for commands
#define StopButton  3
#define LeftSignal  4
#define PosSwitch   5
#define RightSignal 6

CRGB leds[NUM_LEDS1]; // 0-7 left, 8-15 right

byte NTurnLeft  = NUM_LEDS1;
byte NTurnRight = NUM_LEDS1 / 2 - 1;
bool TurnLeft   = false;  //
bool TurnRight  = false;  //
bool Stop       = false;  // stop light on or off ?
bool Position   = true;   // position light on or off ?

const byte BrightnessPos  =  40; // percentage
const byte BrightnessTurn = 100;
const byte BrightnessStop = 100;

unsigned long TurnDur     = 30ul;
unsigned long Chrono      = 0;

void ReadButtons () {
  TurnLeft  = digitalRead(LeftSignal);
  TurnRight = digitalRead(RightSignal);
  Stop      = !digitalRead(StopButton);
  Position  = !digitalRead(PosSwitch);
  delay(20); // for debouncing
}

void TurnSignalRightUp () {
  if (millis() - Chrono > TurnDur) {
    Chrono = millis();
    int orange  = 255 * BrightnessTurn / 100;
    for (int i = NUM_LEDS1 / 2; i < NTurnRight; i++) leds[i] = CRGB(orange, orange, 0);
    NTurnRight ++;
    if (NTurnRight > NUM_LEDS1) {
      NTurnRight = NUM_LEDS1;
      TurnRight = true;
    }
  }
}

void TurnSignalLeftDown () {
  if (millis() - Chrono > TurnDur) {
    Chrono = millis();
    int orange  = 255 * BrightnessTurn / 100;
    for (int i = 0; i < NTurnLeft; i++) leds[i] = CRGB(orange, orange, 0);
    NTurnLeft --;
    if (NTurnLeft < 0) {
      NTurnLeft = 0;
      TurnLeft = true;
    }
  }
}

void LightAll (byte Bright) {
  int red = 255 * Bright / 100;
  fill_solid(leds, NUM_LEDS1, CRGB(red, 0, 0));
}

void setup() {
  FastLED.addLeds<WS2812B, LED_PIN1, GRB>(leds, NUM_LEDS1);
  pinMode (StopButton,  INPUT_PULLUP);
  pinMode (LeftSignal,  INPUT_PULLUP);
  pinMode (PosSwitch,   INPUT_PULLUP);
  pinMode (RightSignal, INPUT_PULLUP);
  Serial.begin(115200);
  Chrono = millis();
}

void loop() {
  ReadButtons ();

  if (!Position) {
    FastLED.clear();               // Position light OFF
  } else LightAll (BrightnessPos); // Position light ON

  if (Stop) LightAll (BrightnessStop);    // Stop light ON

  if (!TurnRight) TurnSignalRightUp ();   // Do the right wave up
  else NTurnRight = NUM_LEDS1 / 2 - 1;
  if (!TurnLeft) TurnSignalLeftDown ();   // Do the left wave down
  else NTurnLeft  = NUM_LEDS1;

  FastLED.show();
}
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: DSGFlash on Oct 29, 2018, 04:44 pm
Try with this
Now it works well (that's what I meant).  ;)  For pin number 4 you have to do the same only LEDs are to light up from the diode: 7 to diode: 0. Mass control must work the same as for pin 6.
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: lesept on Oct 29, 2018, 04:52 pm
Sorry, this must be better for pin 4:
Code: [Select]
#include <FastLED.h>
#define LED_PIN1     2
#define NUM_LEDS1   16

// buttons / switches for commands
#define StopButton  3
#define LeftSignal  4
#define PosSwitch   5
#define RightSignal 6

CRGB leds[NUM_LEDS1]; // 0-7 left, 8-15 right

byte NTurnLeft  = NUM_LEDS1 / 2 - 1;
byte NTurnRight = NUM_LEDS1 / 2 - 1;
bool TurnLeft   = false;  //
bool TurnRight  = false;  //
bool Stop       = false;  // stop light on or off ?
bool Position   = true;   // position light on or off ?

const byte BrightnessPos  =  40; // percentage
const byte BrightnessTurn = 100;
const byte BrightnessStop = 100;

unsigned long TurnDur     = 30ul;
unsigned long Chrono      = 0;

void ReadButtons () {
  TurnLeft  = digitalRead(LeftSignal);
  TurnRight = digitalRead(RightSignal);
  Stop      = !digitalRead(StopButton);
  Position  = !digitalRead(PosSwitch);
  delay(20); // for debouncing
}

void TurnSignalRightUp () {
  if (millis() - Chrono > TurnDur) {
    Chrono = millis();
    int orange  = 255 * BrightnessTurn / 100;
    for (int i = NUM_LEDS1 / 2; i < NTurnRight; i++) leds[i] = CRGB(orange, orange, 0);
    NTurnRight ++;
    if (NTurnRight > NUM_LEDS1) {
      NTurnRight = NUM_LEDS1;
      TurnRight = true;
    }
  }
}

void TurnSignalLeftDown () {
  if (millis() - Chrono > TurnDur) {
    Chrono = millis();
    int orange  = 255 * BrightnessTurn / 100;
    for (int i = 0; i < NTurnLeft; i++) leds[i] = CRGB(orange, orange, 0);
    NTurnLeft --;
    if (NTurnLeft < 0) {
      NTurnLeft = 0;
      TurnLeft = true;
    }
  }
}

void LightAll (byte Bright) {
  int red = 255 * Bright / 100;
  fill_solid(leds, NUM_LEDS1, CRGB(red, 0, 0));
}

void setup() {
  FastLED.addLeds<WS2812B, LED_PIN1, GRB>(leds, NUM_LEDS1);
  pinMode (StopButton,  INPUT_PULLUP);
  pinMode (LeftSignal,  INPUT_PULLUP);
  pinMode (PosSwitch,   INPUT_PULLUP);
  pinMode (RightSignal, INPUT_PULLUP);
  Serial.begin(115200);
  Chrono = millis();
}

void loop() {
  ReadButtons ();

  if (!Position) {
    FastLED.clear();               // Position light OFF
  } else LightAll (BrightnessPos); // Position light ON

  if (Stop) LightAll (BrightnessStop);    // Stop light ON

  if (!TurnRight) TurnSignalRightUp ();   // Do the right wave up
  else NTurnRight = NUM_LEDS1 / 2 - 1;
  if (!TurnLeft) TurnSignalLeftDown ();   // Do the left wave down
  else NTurnLeft  = NUM_LEDS1 / 2 - 1;

  FastLED.show();
}

Do the position lights work (pin 5)?
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: DSGFlash on Oct 29, 2018, 05:17 pm
Pin 4 is still working badly. See the movie that I sent you. The control of this pin 4 must work in the same way as for pin 6, only the LEDs light must be up from: 7 to: 0. Yes, the position lamps are working. The rest works fine except for pin 4
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: lesept on Oct 29, 2018, 05:32 pm
This one must be OK:
Code: [Select]
#include <FastLED.h>
#define LED_PIN1     2
#define NUM_LEDS1   16

// buttons / switches for commands
#define StopButton  3
#define LeftSignal  4
#define PosSwitch   5
#define RightSignal 6

CRGB leds[NUM_LEDS1]; // 0-7 left, 8-15 right

byte NTurnLeft  = NUM_LEDS1 / 2 - 1;
byte NTurnRight = NUM_LEDS1 / 2 - 1;
bool TurnLeft   = false;  //
bool TurnRight  = false;  //
bool Stop       = false;  // stop light on or off ?
bool Position   = true;   // position light on or off ?

const byte BrightnessPos  =  40; // percentage
const byte BrightnessTurn = 100;
const byte BrightnessStop = 100;

unsigned long TurnDur     = 30ul;
unsigned long Chrono      = 0;

void ReadButtons () {
  TurnLeft  = digitalRead(LeftSignal);
  TurnRight = digitalRead(RightSignal);
  Stop      = !digitalRead(StopButton);
  Position  = !digitalRead(PosSwitch);
  delay(20); // for debouncing
}

void TurnSignalRightUp () {
  if (millis() - Chrono > TurnDur) {
    Chrono = millis();
    int orange  = 255 * BrightnessTurn / 100;
    for (int i = NUM_LEDS1 / 2; i < NTurnRight; i++) leds[i] = CRGB(orange, orange, 0);
    NTurnRight ++;
    if (NTurnRight > NUM_LEDS1) {
      NTurnRight = NUM_LEDS1;
      TurnRight = true;
    }
  }
}

void TurnSignalLeftDown () {
  if (millis() - Chrono > TurnDur) {
    Chrono = millis();
    int orange  = 255 * BrightnessTurn / 100;
    for (int i = NUM_LEDS1 / 2; i > NTurnLeft; i--) leds[i] = CRGB(orange, orange, 0);
    NTurnLeft --;
    if (NTurnLeft < 0) {
      NTurnLeft = 0;
      TurnLeft = true;
    }
  }
}

void LightAll (byte Bright) {
  int red = 255 * Bright / 100;
  fill_solid(leds, NUM_LEDS1, CRGB(red, 0, 0));
}

void setup() {
  FastLED.addLeds<WS2812B, LED_PIN1, GRB>(leds, NUM_LEDS1);
  pinMode (StopButton,  INPUT_PULLUP);
  pinMode (LeftSignal,  INPUT_PULLUP);
  pinMode (PosSwitch,   INPUT_PULLUP);
  pinMode (RightSignal, INPUT_PULLUP);
  Serial.begin(115200);
  Chrono = millis();
}

void loop() {
  ReadButtons ();

  if (!Position) {
    FastLED.clear();               // Position light OFF
  } else LightAll (BrightnessPos); // Position light ON

  if (Stop) LightAll (BrightnessStop);    // Stop light ON

  if (!TurnRight) TurnSignalRightUp ();   // Do the right wave up
  else NTurnRight = NUM_LEDS1 / 2 - 1;
  if (!TurnLeft) TurnSignalLeftDown ();   // Do the left wave down
  else NTurnLeft  = NUM_LEDS1 / 2 - 1;

  FastLED.show();
}
(Hopefully :) )
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: DSGFlash on Oct 29, 2018, 05:44 pm
This one must be OK
The direction of the wave is good but the diodes must light up from: 7 to: 0. In this code they light up from: 8 to: 1. After giving the mass on the pin: 4, the wave performs one full cycle and goes out it should shine to the moment of holding the mass. And go out after subtracting the mass. Correct it and it will be fine :)
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: lesept on Oct 29, 2018, 05:51 pm
In function TurnSignalLeftDown, change
Code: [Select]
    for (int i = NUM_LEDS1 / 2; i > NTurnLeft; i--) leds[i] = CRGB(orange, orange, 0);
to
Code: [Select]
    for (int i = NUM_LEDS1 / 2 - 1; i >= NTurnLeft; i--) leds[i] = CRGB(orange, orange, 0);


it should shine to the moment of holding the mass. And go out after subtracting the mass. Correct it and it will be fine :)
Do you mean that the leds (either left or right) must stay ON while led 4 or 6 are at GND?
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: lesept on Oct 29, 2018, 05:58 pm
If this change worked, then try this :

Code: [Select]
#include <FastLED.h>
#define LED_PIN1     2
#define NUM_LEDS1   16

// buttons / switches for commands
#define StopButton  3
#define LeftSignal  4
#define PosSwitch   5
#define RightSignal 6

CRGB leds[NUM_LEDS1]; // 0-7 left, 8-15 right

byte NTurnLeft  = NUM_LEDS1 / 2 - 1;
byte NTurnRight = NUM_LEDS1 / 2 - 1;
bool TurnLeft   = false;  //
bool TurnRight  = false;  //
bool Stop       = false;  // stop light on or off ?
bool Position   = true;   // position light on or off ?

const byte BrightnessPos  =  40; // percentage
const byte BrightnessTurn = 100;
const byte BrightnessStop = 100;

unsigned long TurnDur     = 30ul;
unsigned long Chrono      = 0;

void ReadButtons () {
  TurnLeft  = digitalRead(LeftSignal);
  TurnRight = digitalRead(RightSignal);
  Stop      = !digitalRead(StopButton);
  Position  = !digitalRead(PosSwitch);
  delay(20); // for debouncing
}

void TurnSignalRightUp () {
  if (millis() - Chrono > TurnDur) {
    Chrono = millis();
    int orangeR  = 255 * BrightnessTurn / 100;
    int orangeG  = 150 * BrightnessTurn / 100;
    for (int i = NUM_LEDS1 / 2; i < NTurnRight; i++) leds[i] = CRGB(orangeR, orangeG, 0);
    NTurnRight ++;
    if (NTurnRight > NUM_LEDS1) {
      NTurnRight = NUM_LEDS1;
//      TurnRight = true;
    }
  }
}

void TurnSignalLeftDown () {
  if (millis() - Chrono > TurnDur) {
    Chrono = millis();
    int orangeR  = 255 * BrightnessTurn / 100;
    int orangeG  = 150 * BrightnessTurn / 100;
    for (int i = NUM_LEDS1 / 2 - 1; i >= NTurnLeft; i--) leds[i] = CRGB(orangeR, orangeG, 0);
    NTurnLeft --;
    if (NTurnLeft < 0) {
      NTurnLeft = 0;
//      TurnLeft = true;
    }
  }
}

void LightAll (byte Bright) {
  int red = 255 * Bright / 100;
  fill_solid(leds, NUM_LEDS1, CRGB(red, 0, 0));
}

void setup() {
  FastLED.addLeds<WS2812B, LED_PIN1, GRB>(leds, NUM_LEDS1);
  pinMode (StopButton,  INPUT_PULLUP);
  pinMode (LeftSignal,  INPUT_PULLUP);
  pinMode (PosSwitch,   INPUT_PULLUP);
  pinMode (RightSignal, INPUT_PULLUP);
  Serial.begin(115200);
  Chrono = millis();
}

void loop() {
  ReadButtons ();

  if (!Position) {
    FastLED.clear();               // Position light OFF
  } else LightAll (BrightnessPos); // Position light ON

  if (Stop) LightAll (BrightnessStop);    // Stop light ON

  if (!TurnRight) TurnSignalRightUp ();   // Do the right wave up
  else NTurnRight = NUM_LEDS1 / 2 - 1;
  if (!TurnLeft) TurnSignalLeftDown ();   // Do the left wave down
  else NTurnLeft  = NUM_LEDS1 / 2 - 1;

  FastLED.show();
}
The turn signs should stay lit while pins 4 or 6 are at GND.

I also change the orange color to have it more ... orange :)
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: DSGFlash on Oct 29, 2018, 06:13 pm
In function TurnSignalLeftDown, change
Code: [Select]
   for (int i = NUM_LEDS1 / 2; i > NTurnLeft; i--) leds[i] = CRGB(orange, orange, 0);

to
Code: [Select]
   for (int i = NUM_LEDS1 / 2 - 1; i >= NTurnLeft; i--) leds[i] = CRGB(orange, orange, 0);

Do you mean that the leds (either left or right) must stay ON while led 4 or 6 are at GND?
Ok, I changed the line now, it's shining like it was supposed to be. No no. The turn signal right under pin 6 works well and so is to stay. Look at the movie that I sent to you how the left turn signal behaves after giving a constant mass on pin 4. It should behave the same as diodes on pine 6. When I give the mass to the pin: 4 wave should perform one full cycle and stop. Uncouple the mass and it should go out.
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: lesept on Oct 29, 2018, 06:23 pm
OK, did you try the version of my answer #37?

If you want to get back to before, uncomment lines 44 and 58.
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: DSGFlash on Oct 29, 2018, 06:35 pm
OK, did you try the version of my answer #37?

If you want to get back to before, uncomment lines 44 and 58.
yes, I checked the version from # 37. Correct only the mass control for pin 4. The ground control for pin 4 must be the same as the pin 6 control. The rest works well only you need to improve this mass control for pin 4.
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: lesept on Oct 29, 2018, 06:38 pm
I'll check that this evening. I don't understand why there is a difference between left and right, as the codes are symmetric. I'll try it with an Arduino back home and then I'll have more insight of how it's working inside.
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: DSGFlash on Oct 29, 2018, 06:49 pm
I'll check that this evening. I don't understand why there is a difference between left and right, as the codes are symmetric. I'll try it with an Arduino back home and then I'll have more insight of how it's working inside.

OK I understand
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: lesept on Oct 29, 2018, 07:48 pm
Got it! I always make that mistake, with byte going down below 0 but instead of -1 they come back to 255!
So here is a version which should work:
Code: [Select]
#include <FastLED.h>
#define LED_PIN1     2
#define NUM_LEDS1   16

// buttons / switches for commands
#define StopButton  3
#define LeftSignal  4
#define PosSwitch   5
#define RightSignal 6

CRGB leds[NUM_LEDS1]; // 0-7 left, 8-15 right

byte NTurnLeft  = NUM_LEDS1 / 2 - 1;
byte NTurnRight = NUM_LEDS1 / 2 - 1;
bool TurnLeft   = false;  //
bool TurnRight  = false;  //
bool Stop       = false;  // stop light on or off ?
bool Position   = true;   // position light on or off ?

const byte BrightnessPos  =  40; // percentage
const byte BrightnessTurn = 100;
const byte BrightnessStop = 100;

unsigned long TurnDur     = 30ul;
unsigned long Chrono      = 0;

void ReadButtons () {
  TurnLeft  = digitalRead(LeftSignal);
  TurnRight = digitalRead(RightSignal);
  Stop      = !digitalRead(StopButton);
  Position  = !digitalRead(PosSwitch);
  delay(20); // for debouncing
}

void TurnSignalRightUp () {
  if (millis() - Chrono >= TurnDur) {
    Chrono = millis();
    int orangeR  = 255 * BrightnessTurn / 100;
    int orangeG  = 150 * BrightnessTurn / 100;
    for (int i = NUM_LEDS1 / 2; i < NTurnRight; i++) leds[i] = CRGB(orangeR, orangeG, 0);
    NTurnRight ++;
    if (NTurnRight > NUM_LEDS1) {
      NTurnRight = NUM_LEDS1;
    }
  }
}

void TurnSignalLeftDown () {
  if (millis() - Chrono >= TurnDur) {
    Chrono = millis();
    int orangeR  = 255 * BrightnessTurn / 100;
    int orangeG  = 150 * BrightnessTurn / 100;
    for (int i = NUM_LEDS1 / 2 - 1; i >= NTurnLeft; i--) leds[i] = CRGB(orangeR, orangeG, 0);
    NTurnLeft --;
    if (NTurnLeft > 254) {
      NTurnLeft = 0;
    }
  }
}

void LightAll (byte Bright) {
  int red = 255 * Bright / 100;
  fill_solid(leds, NUM_LEDS1, CRGB(red, 0, 0));
}

void setup() {
  FastLED.addLeds<WS2812B, LED_PIN1, GRB>(leds, NUM_LEDS1);
  pinMode (StopButton,  INPUT_PULLUP);
  pinMode (LeftSignal,  INPUT_PULLUP);
  pinMode (PosSwitch,   INPUT_PULLUP);
  pinMode (RightSignal, INPUT_PULLUP);
//  Serial.begin(115200);
  Chrono = millis();
}

void loop() {
  ReadButtons ();

  if (!Position) {
    FastLED.clear();               // Position light OFF
  } else LightAll (BrightnessPos); // Position light ON

  if (Stop) LightAll (BrightnessStop);    // Stop light ON

  if (!TurnRight) TurnSignalRightUp ();   // Do the right wave up
  else NTurnRight = NUM_LEDS1 / 2 - 1;
  if (!TurnLeft) TurnSignalLeftDown ();   // Do the left wave down
  else NTurnLeft  = NUM_LEDS1 / 2 - 1;

  FastLED.show();
}
Please tell me!
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: DSGFlash on Oct 29, 2018, 08:20 pm
Everything works the way I wanted ;) Thank you very much, lesept  :) . You have a lot of knowledge about programming in Arduino. I do not know how I can thank you. I'm ashamed to continue to ask for help because you've helped me a lot but In the free time if you can improve it to make the emergency lights work. Because now, as I give the mass on pin 4 and pin 6, the rulers change between themselves. It would be good if you could get the effect of emergency lights by giving and removing masses from pins 4 and 6.

Thank you very much !
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: lesept on Oct 29, 2018, 08:40 pm
You mean that if both pins 4 & 6 are LOW, both left and right signs should be synchronized. OK, I'll do it shortly. Do you want that I put only one orange moving led when the stop button is pushed?
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: DSGFlash on Oct 29, 2018, 08:57 pm
I will say it simpler. So that you can use the left and right direction indicators, at the same time . Now, when I plug in the masses on pin 4 and 6 at the same time, the waves change among themselves. Thus, you can not make the effect of hazard lights.
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: lesept on Oct 29, 2018, 09:14 pm
I think it can be done quite simply: try this and tell me...
Code: [Select]
#include <FastLED.h>
#define LED_PIN1     2
#define NUM_LEDS1   16

// buttons / switches for commands
#define StopButton  3
#define LeftSignal  4
#define PosSwitch   5
#define RightSignal 6

CRGB leds[NUM_LEDS1]; // 0-7 left, 8-15 right

byte NTurnLeft  = NUM_LEDS1 / 2 - 1;
byte NTurnRight = NUM_LEDS1 / 2 - 1;
bool TurnLeft   = false;  //
bool TurnRight  = false;  //
bool Stop       = false;  // stop light on or off ?
bool Position   = true;   // position light on or off ?

const byte BrightnessPos  =  40; // percentage
const byte BrightnessTurn = 100;
const byte BrightnessStop = 100;

unsigned long TurnDur     = 30ul;
unsigned long ChronoLeft  = 0;
unsigned long ChronoRight = 0;

void ReadButtons () {
  TurnLeft  = digitalRead(LeftSignal);
  TurnRight = digitalRead(RightSignal);
  Stop      = !digitalRead(StopButton);
  Position  = !digitalRead(PosSwitch);
  delay(20); // for debouncing
}

void TurnSignalRightUp () {
  if (millis() - ChronoRight >= TurnDur) {
    ChronoRight = millis();
    int orangeR  = 255 * BrightnessTurn / 100;
    int orangeG  = 150 * BrightnessTurn / 100;
    for (int i = NUM_LEDS1 / 2; i < NTurnRight; i++) leds[i] = CRGB(orangeR, orangeG, 0);
    NTurnRight ++;
    if (NTurnRight > NUM_LEDS1) {
      NTurnRight = NUM_LEDS1;
    }
  }
}

void TurnSignalLeftDown () {
  if (millis() - ChronoLeft >= TurnDur) {
    ChronoRight = millis();
    int orangeR  = 255 * BrightnessTurn / 100;
    int orangeG  = 150 * BrightnessTurn / 100;
    for (int i = NUM_LEDS1 / 2 - 1; i >= NTurnLeft; i--) leds[i] = CRGB(orangeR, orangeG, 0);
    NTurnLeft --;
    if (NTurnLeft > 254) {
      NTurnLeft = 0;
    }
  }
}

void LightAll (byte Bright) {
  int red = 255 * Bright / 100;
  fill_solid(leds, NUM_LEDS1, CRGB(red, 0, 0));
}

void setup() {
  FastLED.addLeds<WS2812B, LED_PIN1, GRB>(leds, NUM_LEDS1);
  pinMode (StopButton,  INPUT_PULLUP);
  pinMode (LeftSignal,  INPUT_PULLUP);
  pinMode (PosSwitch,   INPUT_PULLUP);
  pinMode (RightSignal, INPUT_PULLUP);
//  Serial.begin(115200);
  ChronoLeft = millis();
  ChronoRight = ChronoLeft;
}

void loop() {
  ReadButtons ();

  if (!Position) {
    FastLED.clear();               // Position light OFF
  } else LightAll (BrightnessPos); // Position light ON

  if (Stop) LightAll (BrightnessStop);    // Stop light ON

  if (!TurnRight) TurnSignalRightUp ();   // Do the right wave up
  else NTurnRight = NUM_LEDS1 / 2 - 1;
  if (!TurnLeft) TurnSignalLeftDown ();   // Do the left wave down
  else NTurnLeft  = NUM_LEDS1 / 2 - 1;

  FastLED.show();
}
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: lesept on Oct 30, 2018, 08:06 am
I added the single led turn signal in case the stop button is pusshed, and corrected a bug. This version should be OK.

Code: [Select]
#include <FastLED.h>
#define LED_PIN1     2
#define NUM_LEDS1   16

// buttons / switches for commands
#define StopButton  3
#define LeftSignal  4
#define PosSwitch   5
#define RightSignal 6

CRGB leds[NUM_LEDS1]; // 0-7 left, 8-15 right

byte NTurnLeft  = NUM_LEDS1 / 2 - 1;
byte NTurnRight = NUM_LEDS1 / 2 + 1;
bool TurnLeft   = false;  //
bool TurnRight  = false;  //
bool Stop       = false;  // stop light on or off ?
bool Position   = true;   // position light on or off ?

const byte BrightnessPos  =  40; // percentage
const byte BrightnessTurn = 100;
const byte BrightnessStop = 100;

unsigned long TurnDur     = 30ul;
unsigned long ChronoLeft  = 0;
unsigned long ChronoRight = 0;

void ReadButtons () {
  TurnLeft  = digitalRead(LeftSignal);
  TurnRight = digitalRead(RightSignal);
  Stop      = !digitalRead(StopButton);
  Position  = !digitalRead(PosSwitch);
  delay(20); // for debouncing
}

void TurnSignalRightUp () {
  if (millis() - ChronoRight >= TurnDur) {
    ChronoRight = millis();
    int orangeR  = 255 * BrightnessTurn / 100;
    int orangeG  = 150 * BrightnessTurn / 100;
    if (Stop) leds[NTurnRight - 1] = CRGB(orangeR, orangeG, 0);
    else for (int i = NUM_LEDS1 / 2; i < NTurnRight; i++) leds[i] = CRGB(orangeR, orangeG, 0);
    NTurnRight ++;
    if (NTurnRight > NUM_LEDS1) {
      NTurnRight = NUM_LEDS1;
    }
  }
}

void TurnSignalLeftDown () {
  if (millis() - ChronoLeft >= TurnDur) {
    ChronoRight = millis();
    int orangeR  = 255 * BrightnessTurn / 100;
    int orangeG  = 150 * BrightnessTurn / 100;
    if (Stop) leds[NTurnLeft] = CRGB(orangeR, orangeG, 0);
    else for (int i = NUM_LEDS1 / 2 - 1; i >= NTurnLeft; i--) leds[i] = CRGB(orangeR, orangeG, 0);
    NTurnLeft --;
    if (NTurnLeft > 254) {
      NTurnLeft = 0;
    }
  }
}

void LightAll (byte Bright) {
  int red = 255 * Bright / 100;
  fill_solid(leds, NUM_LEDS1, CRGB(red, 0, 0));
}

void setup() {
  FastLED.addLeds<WS2812B, LED_PIN1, GRB>(leds, NUM_LEDS1);
  pinMode (StopButton,  INPUT_PULLUP);
  pinMode (LeftSignal,  INPUT_PULLUP);
  pinMode (PosSwitch,   INPUT_PULLUP);
  pinMode (RightSignal, INPUT_PULLUP);
  //  Serial.begin(115200);
  ChronoLeft = millis();
  ChronoRight = ChronoLeft;
}

void loop() {
  ReadButtons ();

  if (!Position) {
    FastLED.clear();               // Position light OFF
  } else LightAll (BrightnessPos); // Position light ON

  if (Stop) LightAll (BrightnessStop);    // Stop light ON

  if (!TurnRight) TurnSignalRightUp ();   // Do the right wave up
  else NTurnRight = NUM_LEDS1 / 2 + 1;
  if (!TurnLeft) TurnSignalLeftDown ();   // Do the left wave down
  else NTurnLeft  = NUM_LEDS1 / 2 - 1;

  FastLED.show();
}
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: DSGFlash on Oct 31, 2018, 11:19 am
Ok, so the code from the post: 47 works as it should.  :)
Thank you again for your help and time. I think the topic is resolved.  :smiley-wink:
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: lesept on Oct 31, 2018, 09:51 pm
Better test the code from answer #48, and use it if you find it ok.
Enjoy! I'd like a picture or video when you install it on your bike...
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: gpdriver on Nov 26, 2018, 03:28 pm
hello guys...good project,this is what I lookig for
I have one question, when I put right turn leds flashing with stroboskope efect ..could someone check it

Best regards

I made the video how screch working https://mega.nz/#!8UgWnYLB!yrfuhI_r_WA0_ck6mV84aVjL4AcnRxpBLGIQ2aXDeYw

thank U
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: lesept on Nov 26, 2018, 09:36 pm
You can slow it down by increasing the value here
Code: [Select]
unsigned long TurnDur     = 30ul;
Try 60 or 100 instead of 30...
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: gpdriver on Nov 27, 2018, 10:42 am
thank U lesept .........value 5 is the best

    everything working like harm
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: lesept on Nov 27, 2018, 04:51 pm
Good !
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: alaminxp on Jun 05, 2019, 07:32 am
I have try to modify this for 2 separate strip one for left and another for right.

not able to success


Anyone can help?
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: AWOL on Jun 05, 2019, 08:16 am
I have try to modify this for 2 separate strip one for left and another for right.

not able to success


Anyone can help?
Without seeing your code?
Not a hope.
Title: Re: Dynamic turn signals stop and parking lights - WS2812b
Post by: alaminxp on Jun 05, 2019, 10:22 pm
Code: [Select]
#include <FastLED.h>

#define LED_PIN1     5
#define LED_PIN     6
#define NUM_LEDS    8

// buttons for commands
#define StopButton 3
#define ClignoButton 8
#define ClignoButtonR 4
#define PosButton 2
#define EmButton 9
#define PoliceButton 10
CRGB leds1[NUM_LEDS];
CRGB leds[NUM_LEDS];

byte NCligno = 0;
byte NClignoR = 0;
bool Cligno = false;
bool ClignoR = false;
bool Stop = false;
bool Em = false;
bool Police = false;
bool Position = true;

const byte BrightnessPos = 4; // %
const byte BrightnessCligno = 10;
const byte BrightnessStop = 10;

unsigned long ClignoDur = 20ul;
unsigned long ClignoDurR = 20ul;
unsigned long Chrono = 0;
unsigned long ChronoR = 0;

void ReadButtons () {
  Cligno = !digitalRead(ClignoButton);
  ClignoR = !digitalRead(ClignoButtonR);
  Stop = !digitalRead(StopButton);
  Position = !digitalRead(PosButton);
  Em = !digitalRead(EmButton);
  Police = !digitalRead(PoliceButton);
  delay(25);
}

void LightCligno (byte n) {
  int orange = 255 * BrightnessCligno / 100;
  for (int i = 0; i < n; i++) leds[i] = CRGB(orange, orange, 0);
}
void LightClignoR (byte n) {
  int orange = 255 * BrightnessCligno / 100;
  for (int i = 0; i < n; i++) leds1[i] = CRGB(orange, orange, 0);
}

void LightAll (byte b) {
  int red = 255 * b / 100;
  for (int i = 0; i < NUM_LEDS; i++) leds1[i] = CRGB(red, 0, 0);
  for (int i = 0; i < NUM_LEDS; i++) leds[i] = CRGB(red, 0, 0);
}
void LightEm (byte n) {
  int orange = 255 * BrightnessCligno / 100;
  for (int i = 0; i < n; i++) leds[i] = CRGB(orange, orange, 0);
  for (int i = 0; i < n; i++) leds1[i] = CRGB(orange, orange, 0);
}

void LightPolice (byte b) {
  int red = 255 * b / 100;
  for (int i = 0; i < b; i++) leds1[i] = CRGB(0, 0, red);
  for (int i = 0; i < b; i++) leds[i] = CRGB(red, 0, 0);
}

void setup() {
  FastLED.addLeds<WS2812, LED_PIN1, GRB>(leds1, NUM_LEDS);
  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  pinMode (StopButton, INPUT_PULLUP);
  pinMode (ClignoButton, INPUT_PULLUP);
  pinMode (ClignoButtonR, INPUT_PULLUP);
  pinMode (PosButton, INPUT_PULLUP);
  pinMode (EmButton, INPUT_PULLUP);
  pinMode (PoliceButton, INPUT_PULLUP);
  Serial.begin(115200);
  Chrono = millis();
  ChronoR = millis();
}

void loop() {
  ReadButtons ();

  if (!Position) {
    FastLED.clear();
  } else LightAll (BrightnessPos);

  if (Stop) LightAll (BrightnessStop);

  if (Cligno) {
    if (millis() - Chrono > ClignoDur) {
      Chrono = millis();
      NCligno = (NCligno + 1) % NUM_LEDS;
      LightCligno (NCligno);
    }

  }
  if (ClignoR) {
    if (millis() - ChronoR > ClignoDurR) {
      ChronoR = millis();
      NClignoR = (NClignoR + 1) % NUM_LEDS;
      LightClignoR (NClignoR);
    }
  }

  if (Em) {
    if (millis() - Chrono > ClignoDur) {
      Chrono = millis();
      NCligno = (NCligno + 1) % NUM_LEDS;
      LightCligno (NCligno);
    }
    if (millis() - ChronoR > ClignoDurR) {
      ChronoR = millis();
      NClignoR = (NClignoR + 1) % NUM_LEDS;
      LightClignoR (NClignoR);
    }
  }

//  if (Police) LightPolice (BrightnessStop);


  if (Police) {
    if (millis() - Chrono > ClignoDur) {
      Chrono = millis();
      NCligno = (NCligno + 1) % NUM_LEDS;
      LightPolice (NCligno);
    }
    if (millis() - ChronoR > ClignoDurR) {
      ChronoR = millis();
      NClignoR = (NClignoR + 1) % NUM_LEDS;
      LightPolice (NClignoR);
    }
  }

 
  FastLED.show();
}


I have done 2 separate Strip.

Now here is the problem with police light animation
I am not able to achieve the result like police Light Effect.