SoftPWM auto off feature

I am trying to use the softPWM library to fade blink some LED’s on nonPWM pins.

Currently the basic code is like this:

#include <SoftPWM.h>

void setup()
{
  SoftPWMBegin();
  
  SoftPWMSet(13, 0);

  SoftPWMSetFadeTime(13, 1000, 1000);
}

void loop()
{
  SoftPWMSet(13, 255);
  delay(1000);
  SoftPWMSet(13, 0);
  delay(1000);
}

However I was wondering if there is anyway to set the PWM to go up to a certain level and back down in one command rather than having to call it two commands. An example would be calling something like this: SoftPWMSet(13,255,0); which would PWM the led to full brightness and then down to zero. I need this feature since it becomes hard to properly turn off an LED once it has reached full brightness once you start adding other code and you dont have the clean delay functions to keep exact time.

Anyone have any suggestions on how to accomplish that? Essentially rather than just pseudo-threading the pwm in one direction, but rather threading the pwm in both directions.

Thanks!

bump?

You write a function to do that? I’m not sure I understand where the complexity is.

Would I have to use interrupts to do so? Since if I wrote a function that used delay, the delay would simply freeze the whole program and would not be useful. And so the interrupt would have to trigger at the same time as the pin reached a certain value?

I'm not familiar with the SoftPWM library, but one approach would be to use a timer to cause an interrupt every few milliseconds. In that interrupt you could change the PWM value.

Stuff about timers: