Coder Social home page Coder Social logo

Comments (16)

jgillick avatar jgillick commented on June 28, 2024

This is an odd one. What happens when you try to use it? I assume the LED doesn't come on at all?

Here's my theory: The library doesn't set the pin output mode itself and D0 is by default RX, which would be an input pin. Try this line in the setup() method:

pinMode(0, OUTPUT);

I don't think it has anything to do with the line you referenced in the header. That's just a default initialization and if you pass the pin number explicitly, that will be ignored.

from arduino-ledfader.

RossAWaddell avatar RossAWaddell commented on June 28, 2024

Unfortunately, that didn't work. I even added:

UCSR0B = 0;

but that didn't help, either. And yes, the LED doesn't come on at all.

EDIT: Also, regular analogWrite(0,255); works, as does other LED libraries like jLed.

from arduino-ledfader.

jgillick avatar jgillick commented on June 28, 2024

That's really odd. Offhand I'm not sure why that would happen. I'll see if I have any Atmega 328PB chips lying around I can try this on.

from arduino-ledfader.

jgillick avatar jgillick commented on June 28, 2024

Just out of curiosity, does led.set_value(125); set the LED to half brightness?

from arduino-ledfader.

RossAWaddell avatar RossAWaddell commented on June 28, 2024

Same result - the LED does not light.

#define LED_PIN 0
LEDFader led;

void setup() {
  led = LEDFader(LED_PIN);
  led.set_value(125);
}

void loop() {
  led.update();
}

from arduino-ledfader.

jgillick avatar jgillick commented on June 28, 2024

Ah ha! I think I found the problem:
https://github.com/jgillick/arduino-LEDFader/blob/master/LEDFader.cpp#L30

The code is first checking if the pin has been set. Well pin 0 is equivalently false. You can remove any of those lines. I'll try to update the library soon, but would also take a pull request if someone else wanted to take a stab at it. The library needs to be initialized with a pin, so those checks are likely moot.

from arduino-ledfader.

RossAWaddell avatar RossAWaddell commented on June 28, 2024

That's definitely the issue - if I comment out:

   // No pin defined
  //if (!pin) {
  //    return;
  //}

then all works as expected.

I would happily do a pull request for this, but wanted to check with you first - is it sufficient to just remove those checks from all functions, or would it be better to initialize the class with a signed int instead, as in:

// Create a new LED Fader for a pin
    LEDFader(int pwm_pin=-1);

Then the checks can remain, but like this:

   // No pin defined
  if (pin == -1) {
      return;
  }

from arduino-ledfader.

jgillick avatar jgillick commented on June 28, 2024

I think it's safe to remove those checks entirely. A pin must be defined at initialization, so the checks are really unnecessarily. Thank you!

from arduino-ledfader.

RossAWaddell avatar RossAWaddell commented on June 28, 2024

Ok, I’ll remove them and submit a pull request.

from arduino-ledfader.

RossAWaddell avatar RossAWaddell commented on June 28, 2024

Done

from arduino-ledfader.

jgillick avatar jgillick commented on June 28, 2024

Great. Did you submit a pull request?

from arduino-ledfader.

RossAWaddell avatar RossAWaddell commented on June 28, 2024

I did, although this is my first Github pull request. Do you not see it?

from arduino-ledfader.

jgillick avatar jgillick commented on June 28, 2024

It would show up here:
https://github.com/jgillick/arduino-LEDFader/pulls

Can you send me a link to it?

from arduino-ledfader.

RossAWaddell avatar RossAWaddell commented on June 28, 2024

from arduino-ledfader.

RossAWaddell avatar RossAWaddell commented on June 28, 2024

It is showing up now under Pull requests.

from arduino-ledfader.

jgillick avatar jgillick commented on June 28, 2024

Got it and merged! Thanks @RossAWaddell, I really appreciate the help on this one.

from arduino-ledfader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.