Led effect like daytime running lights and left or right turn

Hello everyone.
I have a question about the effect that is nowadays in many new cars. Namely, it is about daytime running lights and turn signals. That is, if the daytime running lights are on and the turn signal is turned on, the daytime running light goes out and the turn signal starts flashing and when the turn signal finishes flashing, the daytime running light automatically comes on.... (or returns to the state before flashing, ie daytime running lights on or off )
of course, I understand that the daytime running lights will have to be separated into left and right (two pins D1 and D2) because otherwise two diodes would go out.
therefore my code more or less looks like this. And everything is controlled from the phone as a webserver AP.
AND now how to achieve such an effect.... something like in the youtube video...:
thanks in advance for the answer
(please forgive me if something is not understandable because I use an online translator)
Of course, in coding I'm the one who is weak. I can at most make minor adjustments to existing code so I would appreciate some examples.
youtube : (effect of daytime running lights and turn signals) 0:07 sec to 0:20 sec

and this is my code (code section)

//headligt left
{
  if (server.hasArg("key1")) {
  ledStatePinD0 = ! ledStatePinD0;
  digitalWrite(PinD1, ledStatePinD1); // headlight left
}

// turn signal left
  if (server.hasArg("key2")) {
  for (int x = 0; x < 5; x++) {
  digitalWrite(PinD3, HIGH);
  delay(500);
  digitalWrite(PinD3, LOW);
  delay(500);
  }
}

//headligt right
{
  if (server.hasArg("key3")) {
  ledStatePinD2 = ! ledStatePinD2;
  digitalWrite(PinD2, ledStatePinD2); // headlight right
}

// turn signal left
  if (server.hasArg("key4")) {
  for (int x = 0; x < 5; x++) {
  digitalWrite(PinD4, HIGH);
  delay(500);
  digitalWrite(PinD4, LOW);
  delay(500);
  }
}

why not simply turn off the daytime lights while the turn signal is active


    if (swTurnLeft) {
        dayTime (Off);
        flash (lightLeft);
    }
    else if (swTurnRight) {
        dayTime (Off);
        flash (lightRight);
    }
    else
        dayTime (On);


void
flash (
    int pin )
{
    if (millis() - msec0 >= MsecPeriod) {
        msec0 = millis();
        digitalWrite (pin, ! digitalRead (pin));
    }
}

Ok your code is better because it works without delay.
only that i am trying to adapt to my code because in general i more or less know how to change some values and add new diodes.... while your code is less clear to me and I would have to reconfigure my entire code that I have and this involves additional questions and pestering people here on the forum to get the answer .... I don't know if you would mentally stand it :slight_smile:

that's why I thought that to my code I could somehow add these expressions like “else”, “if” .... etc..
to make it work as I would like.
(sorry my english .. I use the translator)

Daytime Running Lights (DRL) are not implemented the same way on every car. In the set I worked on, we used PWM (Pulse Width Modulation) to control the low-beam filament. When switching to the turn signal, the headlight was turned off, but because the filament was still hot, it dimmed slowly rather than shutting off instantly.

If your car has tungsten lamps, try turning the lights on and off to observe this behavior.

{
    // turn signal left
    if (server.hasArg("key2")) {
        digitalWrite (PinD1, Off); // headlight left
        for (int x = 0; x < 5; x++) {
            digitalWrite (PinD3, HIGH);
            delay        (500);
            digitalWrite (PinD3, LOW);
            delay        (500);
        }
        digitalWrite (PinD1, On);  // headlight left
    }

Everything would be fine if it was a real car and its lighting. In this case, however, it's a toy in 1:24 scale and I wanted to achieve the effect that when the indicators (or hazard lights) are on, the daytime running lights go out :slight_smile:
(sorry for my English if something is not understandable)

oo and this code has already brought me a little closer to my goal.
But there is a small problem....
because when, for example, the daytime running lights are off and I turn on the turn signal then after the flashing is over the daytime running light diode comes on ....
so it would have to relate somehow to the status of the daytime running lights whether they were on or not.... and this is where the next problem comes in.

currently the code looks more or less like this:

  if (server.hasArg("key1")) {
  ledStatePinD1 = ! ledStatePinD1;
  ledStatePinD2 = ! ledStatePinD2;
  digitalWrite(PinD1, ledStatePinD1); // światła lewy  (headlight left)
  digitalWrite(PinD2, ledStatePinD2); // światła prawy (headlight right)

  
}

// kierunek lewy kierowcy
  if (server.hasArg("key2")) {
  digitalWrite (PinD1, LOW); // headlight left
  for (int x = 0; x < 5; x++) {
  digitalWrite(PinD3, HIGH);
  delay(500);
  digitalWrite(PinD3, LOW);
  delay(500);
  }
  digitalWrite (PinD1, HIGH);  // headlight left
}
  // kierunek prawy pasaĹĽer
   if (server.hasArg("key3")) {
   digitalWrite (PinD2, LOW);
   for (int x = 0; x < 5; x++) {
   digitalWrite(PinD4, HIGH);
   delay(500);
   digitalWrite(PinD4, LOW);
   delay(500);
  }
  digitalWrite (PinD2, HIGH);
}
  // Emergency
   if (server.hasArg("key4")) {
    digitalWrite (PinD1, LOW);
    digitalWrite (PinD2, LOW);
   for (int x = 0; x < 5; x++) {
     digitalWrite(PinD3, HIGH);
     digitalWrite(PinD4, HIGH);
     delay(500);
     digitalWrite(PinD3, LOW);
     digitalWrite(PinD4, LOW);
     delay(500);
    }
    digitalWrite (PinD1, HIGH);
    digitalWrite (PinD2, HIGH);
    // turn signal left
    if (server.hasArg("key2")) {
        int state = digitalRead (PinD1);
        digitalWrite (PinD1, Off); // headlight left
        for (int x = 0; x < 5; x++) {
            digitalWrite (PinD3, HIGH);
            delay        (500);
            digitalWrite (PinD3, LOW);
            delay        (500);
        }
        digitalWrite (PinD1, state);  // headlight left
    }
1 Like

So, if the headlights are ON, the DRLs should be OFF.
If left turn signal is ON, left DRL should be OFF.
If right turn signal is ON, right DRL should be OFF.
If hazard flashers are ON DRLs should be OFF.
Otherwise, DRLs are ON.
Does that sound right?

1 Like

Eye candy.

No, no... apparently I wrote wrong on the sketch and something else came out .
headlights (that's the whole lamp) and in headlights is DLR, parking lights, long lights.
AND I meant only DLR . :slight_smile:

well that is exactly what I meant....
i just had a little problem with the hazard lights because i thought that if in the
left turn is:
int state = digitalRead (PinD1);
and in the right turn:
int state = digitalRead (PinD2);
so in the emergency will be:
int state = digitalRead (PinD1);
int state = digitalRead (PinD2);

But when verifying the code, an error popped up....
and the correct version of the emergency lights is :

if (server.hasArg("key4")) {
    int state = digitalRead (PinD1);   // PinD1 or PinD2 
    digitalWrite (PinD1, LOW);
    digitalWrite (PinD2, LOW);
   for (int x = 0; x < 5; x++) {
     digitalWrite(PinD3, HIGH);
     digitalWrite(PinD4, HIGH);
     delay(500);
     digitalWrite(PinD3, LOW);
     digitalWrite(PinD4, LOW);
     delay(500);
    }
    digitalWrite (PinD1, state);
    digitalWrite (PinD2, state);

So thank you gcjr for your help and time spent for me. :vulcan_salute: :+1: :slight_smile:

interesting channel... I don't know if it's yours or someone else's but in any case I decided to subscribe and then I'll watch for myself

That channel does "matchbox" car modifications with lights, servos, motors and MCUs.

This guy does (did) automobile light modification. I am not sure his lights are bright enough for outside use, unless he purchases monochrome, superbright WS2812 (or similar). https://www.youtube.com/@IonutFedaceag

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.