Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LowActive() causes weird Fade behaviour #128

Open
RossAWaddell opened this issue Jul 24, 2024 · 5 comments
Open

LowActive() causes weird Fade behaviour #128

RossAWaddell opened this issue Jul 24, 2024 · 5 comments

Comments

@RossAWaddell
Copy link

RossAWaddell commented Jul 24, 2024

I need to connect the -ve pin of LEDs to the Arduino as I'm using a ULN2803A transistor to power 10 5mm LEDs. As this is the opposite of the usual single LED connection I'm using the LowActive() method to invert the fade, but it does a weird blip at the beginning which I don't see when connecting the +ve LED lead to the Arduino pin.

Any idea what's happening here? Ideally I'd like a smooth fade from off to the max brightness value.

+ve LED Lead Connected to Arduino Pin

#include <jled.h>

#define AMBER_LED_PIN 3
#define AMBER_LED_FADE_UP_TIME 4000// Time to power up (power first turned on)
#define PULSE_TIME 1200            // Fade down/up pulse time
#define MAX_BRIGHT_AMBER_LEDS 220
#define MIN_BRIGHT_AMBER_LEDS 110

JLed leds[] = {
JLed(AMBER_LED_PIN).FadeOn(AMBER_LED_FADE_UP_TIME).MaxBrightness(MAX_BRIGHT_AMBER_LEDS).DelayAfter(250),
    JLed(AMBER_LED_PIN).Fade(MAX_BRIGHT_AMBER_LEDS, MIN_BRIGHT_AMBER_LEDS, PULSE_TIME/2),
    JLed(AMBER_LED_PIN).Breathe(PULSE_TIME).MaxBrightness(MAX_BRIGHT_AMBER_LEDS)
      .MinBrightness(MIN_BRIGHT_AMBER_LEDS).DelayAfter(250).Forever()
};

JLedSequence amberLEDseq(JLedSequence::eMode::SEQUENCE, leds);

void setup() { }

void loop() {
    amberLEDseq.Update();
}

YouTube video

-ve LED Lead Connected to Arduino Pin w/ LowActive()

#include <jled.h>

#define AMBER_LED_PIN 3
#define AMBER_LED_FADE_UP_TIME 4000// Time to power up (power first turned on)
#define PULSE_TIME 1200            // Fade down/up pulse time
#define MAX_BRIGHT_AMBER_LEDS 220
#define MIN_BRIGHT_AMBER_LEDS 110

JLed leds[] = {
JLed(AMBER_LED_PIN).LowActive().FadeOn(AMBER_LED_FADE_UP_TIME).MaxBrightness(MAX_BRIGHT_AMBER_LEDS).DelayAfter(250),
    JLed(AMBER_LED_PIN).LowActive().Fade(MAX_BRIGHT_AMBER_LEDS, MIN_BRIGHT_AMBER_LEDS, PULSE_TIME/2),
    JLed(AMBER_LED_PIN).LowActive().Breathe(PULSE_TIME).MaxBrightness(MAX_BRIGHT_AMBER_LEDS)
      .MinBrightness(MIN_BRIGHT_AMBER_LEDS).DelayAfter(250).Forever()
};

JLedSequence amberLEDseq(JLedSequence::eMode::SEQUENCE, leds);

void setup() { }

void loop() {
    amberLEDseq.Update();
}

YouTube video

@jandelgado
Copy link
Owner

Hi @RossAWaddell,

  • which Arduino model are you using?
  • Is there a difference if you are not using the transistor and just driving a single LED?
  • could you please provide the circuit so I can try to re-build it?

@RossAWaddell
Copy link
Author

Hi @jandelgado ,

  • Arduino Uno
  • If I use a Darlington transistor (e.g. ULN2803A) then I don't need to use LowActive() and everything works perfectly. But if I use just a NPN transistor, then it behaves the same as when driving a single LED
  • See Fritzing schematic below
Screenshot 2024-08-20 at 1 35 50 PM Screenshot 2024-08-20 at 1 36 07 PM

@jandelgado
Copy link
Owner

Hi @RossAWaddell ,

I did some testing, and it seems that it has to do with the GPIO port initialization (pinMode()) during which the Arduino SDK will set the level to 0, wich causes the visible blip when using a low-active connection. As a workaround, try the following:

void setup() { 
  // add this line
  ::digitalWrite(AMBER_LED_PIN, HIGH);
}

@RossAWaddell
Copy link
Author

RossAWaddell commented Aug 31, 2024

Thanks! I'll give it a try.

EDIT: I think there's no change. Strangely, the magnitude of the 'blip' seems to be somewhat random - when I hit the reset button on the Uno the blip doesn't appear to be the same every time. In the video the 2nd restart shows the blip more than the first.

https://youtu.be/WrWfJQgCXJk

#include <jled.h>

#define AMBER_LED_PIN 3
#define AMBER_LED_FADE_UP_TIME 4000// Time to power up (power first turned on)
#define PULSE_TIME 1200            // Fade down/up pulse time
#define MAX_BRIGHT_AMBER_LEDS 220
#define MIN_BRIGHT_AMBER_LEDS 110

JLed leds[] = {
JLed(AMBER_LED_PIN).LowActive().FadeOn(AMBER_LED_FADE_UP_TIME).MaxBrightness(MAX_BRIGHT_AMBER_LEDS).DelayAfter(250),
    JLed(AMBER_LED_PIN).LowActive().Fade(MAX_BRIGHT_AMBER_LEDS, MIN_BRIGHT_AMBER_LEDS, PULSE_TIME/2),
    JLed(AMBER_LED_PIN).LowActive().Breathe(PULSE_TIME).MaxBrightness(MAX_BRIGHT_AMBER_LEDS)
      .MinBrightness(MIN_BRIGHT_AMBER_LEDS).DelayAfter(250).Forever()
};

JLedSequence amberLEDseq(JLedSequence::eMode::SEQUENCE, leds);

void setup() { 
  digitalWrite(AMBER_LED_PIN, HIGH);
}

void loop() {
  amberLEDseq.Update();
}

@jandelgado
Copy link
Owner

I did some more tests. What probably helps in your case is to add a delay(25) to the main loop(). In my tests that eliminated the blip on startup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants