So I have stumbled onto a fork of the original SoftPWM library. GitHub - per1234/PalatisSoftPWM: Software PWM library for Arduino But unfortunately as I've mentioned before I tend to have a hard time translating examples into something I understand and can implement. Using this snippet from my code:
case rSTATE1:
{
//initialize things
cycle = 0;
analogWrite(led2, random(randomLowLevel, randomHighLevel));
random2Interval = random(randomLowInterval,randomHighInterval);
led2Millis = currentMillis;
I know what it does because it was written by @Larryd, and then added to by me.
But I've run out of PWM pins and I am aware of the TLC5940 but I don't want to add more electronics beyond what I have. Anyways from that fork, I have an example in the library which I understand what it does. It blinks an LED but I don't know how to translate this syntax to the snippet to make the LED randomly blink/
#include <PalatisSoftPWM.h>
SOFTPWM_DEFINE_PIN13_CHANNEL(0); //Configure Arduino pin 13 as PWM channel 0
SOFTPWM_DEFINE_OBJECT(1);
const unsigned int fadeDuration = 1000; // (ms)The length of time for to go from PWM value 0 to the highest level and back to 0 again. The maximum allowed value is 8388.
void setup() {
PalatisSoftPWM.begin(60); // begin with 60 Hz PWM frequency
}
void loop() {
// fade from PWM value 0 to the highest value
for (byte value = 0; value < PalatisSoftPWM.PWMlevels() - 1; value++) {
delayMicroseconds(fadeDuration * 1000UL / PalatisSoftPWM.PWMlevels() / 2);
PalatisSoftPWM.set(0, value);
}
// fade back to PWM value 0
for (int value = PalatisSoftPWM.PWMlevels() - 1; value >= 0; value--) {
delayMicroseconds(fadeDuration * 1000UL / PalatisSoftPWM.PWMlevels() / 2);
PalatisSoftPWM.set(0, value);
}
}
So in conclusion, how do I translate this library syntax to blink say...led 5 at pin13? Not necessarily asking for the code (although it would be generous) but can someone walk my through how to change it so I can learn it? Please keep in mind I do have a comprehension problem.