DigitalWrite different brightness on the same pin...but why?!

Hey Guys,
actually I have a problem with my code and I just can not solve it. I was working on it for a while now, but I couldn´t find the problem...

If I set the "links" to 1, the left LED is Blinking, but it´s not on full brightness.
The same problem appears if I set the "rechts" to 1, the right LED is blinking, but not on full brightness.

But if I set the "Warnblinker" to 1, both LED´s are blinking with full brightness. I just can find out why the brightness is different, because I´m using the digitalWrite function for all the actions...

Sorry if my english is not the best. I´m from Germany...

Here is the part of my Code:

if (currentMillis - previousMillis >= BlinkGeschw)  //BlinkerLED an und aus setzen nach ablauf der BlinkGeschw
  {
     previousMillis = currentMillis;

    if (BlinkStatus == LOW)
    {
      BlinkStatus = HIGH;
    }
    else
    {
      BlinkStatus = LOW;
    }
  }


  if (links == 1)
  {
    digitalWrite(ledLinks, BlinkStatus);    //Blinker links = BlinkStatus (ein/aus der LED)
    
 /*   if (rechts == 1)   //Blinker ersetzung
    {  
      rechts = 0;
    }*/
  }
  
  if (links == 0)
  {
    digitalWrite(ledLinks, LOW);
  }


  if (rechts == 1)
  {
    digitalWrite(ledRechts, BlinkStatus);   //Blinker rechts = BlinkStatus (ein/aus der LED)
   
  /*  if (links == 1) //Blinker ersetzung
    {    
      links = 0;
    }*/
  }
  
  if (rechts == 0)
  {     
    digitalWrite(ledRechts, LOW);
  }

//Warnblinker:
  if (Warnblinker == 1)
  {
    digitalWrite(ledLinks, BlinkStatus);    //Blinker links = BlinkStatus (ein/aus der LED)
    digitalWrite(ledRechts, BlinkStatus);   //Blinker rechts = BlinkStatus (ein/aus der LED)
  }
  if (Warnblinker == 0)
  {
    digitalWrite(ledLinks, LOW);
    digitalWrite(ledRechts, LOW);
  }
 if (BlinkStatus == LOW)
    {
      BlinkStatus = HIGH;
    }
    else
    {
      BlinkStatus = LOW;
    }
  }


  if (links == 1)
  {
    digitalWrite(ledLinks, BlinkStatus);    //Blinker links = BlinkStatus (ein/aus der LED)
    
 /*   if (rechts == 1)   //Blinker ersetzung
    {  
      rechts = 0;
    }*/
  }
  
  if (links == 0)
  {
    digitalWrite(ledLinks, LOW);
  }

Aka

BlinkStatus = (HIGH + LOW) - BlinkStatus;
digitalWrite(ledLinks, (links ==1) ? BlinkStatus : LOW);

Please, please use code tags when posting code.

Hey, yes, I just editet with the code tags...Sorry for that :slight_smile:

Could you explain your Code? I´m not understanding all of those commands.

Here is the part of my Code:

So why do you not post all of it?

The rules How to use this forum
tell you to post all your code.

If someone is asking about what is wrong with code, then do you think they know enough to post the code containing the error? That is why all code is required.

Grumpy_Mike:
So why do you not post all of it?

The rules How to use this forum
tell you to post all your code.

If someone is asking about what is wrong with code, then do you think they know enough to post the code containing the error? That is why all code is required.

Because you can only post 9000 characters in one Post, my code has about 350 lines and exeeds the limit of 9000 characters…

Then attach it. If you would read the "How to Use This Forum" thread instead of just skipping the rules and instructions you'd know that.

Or write a small sketch that still demonstrates the problem.

Here you have it. I read the rules, but if it isn´t possible I can´t do it…sorry

Lichtsteuerung3.4.ino (9.46 KB)

  1. You can add attachments

If your code is too long to fit into a post, or you have multiple files (eg. code and libraries), or you want to show an image, click on the Additional Options button:

That's in the rules. Hardly impossible. You just did it.

Did you also read the bit where you had to say what the code does and what you wanted it to do?
Given that all the variable names and comments appears to be in German, and my German is limited to ordering three large beers and asking for the bill ( well I know a bit more but not much ) then it is difficult to follow.

It is hard to reconcile that with your initial post.
So I can just give you hints as to what might be going wrong.

If an LED is dim and it should not be then there are two possible causes

  1. You are using analog write to control it and you are giving the wrong value.
  2. You are using digital write and are somehow turning it on and off rapidly. This could be by incorrect use of an else function or lack of time when it is actually on.

The advice to "write a simple program that illustrates your problem" is good advice but here I suspect that it is the complexity of your code that is causing you to miss the bit that is erroneously turning off your LED, assuming that you are using 2)

Grumpy_Mike:
2) You are using digital write and are somehow turning it on and off rapidly. This could be by incorrect use of an else function or lack of time when it is actually on.

The advice to "write a simple program that illustrates your problem" is good advice but here I suspect that it is the complexity of your code that is causing you to miss the bit that is erroneously turning off your LED, assuming that you are using 2)

So, I was experimenting now for a while and wansn´t really finding the problem. I checked many values that are changing while the programm runs with the Serial monitor, but all seems to be OK.

So what I now did, is just add a delay of 1ms [delay(1);] to the if-function wich was setting the LED pin high or low. Now it´s just working how I wanted it to bee...don´t ask me why :smiley:

Thanks to all wich tried to help me!

Grumpy_Mike:
my German is limited to ordering three large beers

Implicit in that, is that they serve small beers in Germany. How can that be?