led pwm

Posted on
  • Is appears that only one of the LEDs can be sent a PWM signal at once – the following will result in only LED2 being lit. Is this a hardware limitation? Can't find anything definitive.

    analogWrite(LED1, 0.2);
    analogWrite(LED2, 0.15);
    
  • At the moment it's a firmware issue that'll be solved in a later update - just one of the hardware PWMs is exposed at the moment.

    You can easily work around it using software PWM with analogWrite(LED1, 0.2, {soft:true}); though, then you can run pretty much as many as you want (albeit at lower speeds).

  • I tried with soft: true and forceSoft: true and got weird results. Not important though, I'll try this again once the firmware is updated – I can just offset the LEDs for now and make sure only one is on at a time.

  • Looks like i was wrong about soft:true, but I just had a quick look and you can get something working with the following:

    function t() {
      analogWrite(LED1,0.1+0.09*Math.sin(getTi­me()), {freq:100,forceSoft:true});
      analogWrite(LED2,0.1+0.09*Math.sin(getTi­me()*1.2324), {freq:100,forceSoft:true});
      analogWrite(LED3,0.1+0.09*Math.sin(getTi­me()*1.4634), {freq:100,forceSoft:true});
    }
    setInterval(t, 50);
    

    Looks like there's a glitch with multiple soft PWM when you give some a value of 0 though (hence the 0.1+0.09*x).

  • Ah, I was getting bright flashes, presumably that's the zero glitch? Still seeing some weirdness with the above, but closer to what I was aiming for, thanks.

  • Just to add, the 1v90 firmware fixes this - making software PWM work better but also allowing you to use multiple hardware PWM channels - it means the original code should now work too.

  • Updated my Pucks last night and removed the forceSoft option, working absolutely perfectly now, thanks so much.

    I've just read your email and know you won't see this under after Xmas, so hope you had a great holiday!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

led pwm

Posted by Avatar for Drarok @Drarok

Actions