Go Down

### Topic: Dynamic turn signals stop and parking lights - WS2812b (Read 5026 times)previous topic - next topic

#### DSGFlash

#15
##### 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.

#### lesept

#16
##### 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 ?
A force d'essayer on finit par réussir... Donc, plus ça rate, plus on a de chances que ça marche (proverbe Sharduinok).

#### DSGFlash

#17
##### Oct 28, 2018, 08:10 pmLast Edit: Oct 28, 2018, 08:17 pm by DSGFlash
I will manage the change in speed.

#### lesept

#18
##### Oct 28, 2018, 11:21 pm
A force d'essayer on finit par réussir... Donc, plus ça rate, plus on a de chances que ça marche (proverbe Sharduinok).

#### lesept

#19
##### 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?
A force d'essayer on finit par réussir... Donc, plus ça rate, plus on a de chances que ça marche (proverbe Sharduinok).

#### lesept

#20
##### Oct 29, 2018, 10:04 amLast Edit: Oct 29, 2018, 10:26 am by lesept
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 6CRGB leds[NUM_LEDS1]; // 0-7 left, 8-15 rightbyte NTurn = 0;bool Mass      = false;  // received mass signal ?bool MassOld   = false;  // previous valuebool TurnState = false;  // turn light on or off ?bool TurnDir   = false;  // true : right, false : leftbool TurnUp    = true;   // true : lights from 0 to 7, false : the other waybool Stop      = false;  // stop light on or off ?bool Position  = true;   // position light on or off ?const byte BrightnessPos  =  40; // percentageconst 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
A force d'essayer on finit par réussir... Donc, plus ça rate, plus on a de chances que ça marche (proverbe Sharduinok).

#### DSGFlash

#21
##### 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.

#### lesept

#22
##### 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 6CRGB leds[NUM_LEDS1]; // 0-7 left, 8-15 rightbyte NTurn = 0;bool Mass      = false;  // received mass signal ?bool MassOld   = false;  // previous valuebool TurnState = false;  // turn light on or off ?bool TurnDir   = false;  // true : right, false : leftbool TurnUp    = true;   // true : lights from 0 to 7, false : the other waybool Stop      = false;  // stop light on or off ?bool Position  = true;   // position light on or off ?const byte BrightnessPos  =  40; // percentageconst 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.
A force d'essayer on finit par réussir... Donc, plus ça rate, plus on a de chances que ça marche (proverbe Sharduinok).

#### lesept

#23
##### 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:
• pin 6 rising from HIGH to LOW (or is it just pin 6 LOW?): launch the wave up from 8 to 15 and wait.
• pin 6 falling from LOW to HIGH (or just pin 6 HIGH?): launch the wave from 15 down to 8 and wait.
And the same for the left sign:
• pin 4 from HIGH to LOW: launch the wave down from 7 to 0 and wait.
• pin 4 from LOW to HIGH: launch the wave from 0 up to 7 and wait.
Is this correct ?

I'll work on that shortly.
A force d'essayer on finit par réussir... Donc, plus ça rate, plus on a de chances que ça marche (proverbe Sharduinok).

#### lesept

#24
##### 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 6CRGB leds[NUM_LEDS1]; // 0-7 left, 8-15 rightbyte NTurnLeft  = 8;byte NTurnRight = 7;bool TurnLeft   = false;  //bool WasLeft    = false;  // previous value for left lightbool TurnRight  = false;  //bool WasRight   = false;  // previous value for roght lightbool Stop       = false;  // stop light on or off ?bool Position   = true;   // position light on or off ?const byte BrightnessPos  =  40; // percentageconst 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...
A force d'essayer on finit par réussir... Donc, plus ça rate, plus on a de chances que ça marche (proverbe Sharduinok).

#### DSGFlash

#25
##### Oct 29, 2018, 01:31 pmLast Edit: Oct 29, 2018, 01:51 pm by DSGFlash
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

#### lesept

#26
##### Oct 29, 2018, 01:55 pmLast Edit: Oct 29, 2018, 01:59 pm by lesept
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
A force d'essayer on finit par réussir... Donc, plus ça rate, plus on a de chances que ça marche (proverbe Sharduinok).

#### DSGFlash

#27
##### Oct 29, 2018, 02:02 pmLast Edit: Oct 29, 2018, 02:47 pm by DSGFlash
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:

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;

#### lesept

#28
##### Oct 29, 2018, 03:16 pm

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 6CRGB leds[NUM_LEDS1]; // 0-7 left, 8-15 rightbyte 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; // percentageconst 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();}`
A force d'essayer on finit par réussir... Donc, plus ça rate, plus on a de chances que ça marche (proverbe Sharduinok).

#29