Okay, I've finally exhausted my search-for-answer capabilities. It's probably out there somewhere, I just don't know how to find it. And, please forgive me if my code is difficult to read; I'm posting from my ipad, so cut-n-paste from Arduino is not very simple.
I've written a sketch that I can easily manipulate to adjust the "fade up" and "fade down" patterns of multiple LEDs. I've gotten it whittled down to two main functions (one for "up", one for "down", and I can just insert which LEDs I want them to control when I call them from Loop.
I believe there must be a way to further simplify it so that I am calling only one function, and I can tell it whether to increase or decrease. I'm just not sure how.
Here's the code for the two functions I want to "combine" —
void FadeUp(int B, int L) { // B = which "Brightness", L = which "LED"
// Loop until led "faded" up to full brightness:
for (int B = 1; B <= 255; B++) {
// set the PWM brightness of led:
analogWrite (L, B);
// change the brightness for next time through the loop:
B = B + fadeAmount;
// Verify potentiometer setting
checkPot();
// wait for "DelayTime" milliseconds to see the dimming effect
delay(DelayTime);
}
}
void FadeDown(int B, int L) { // B = which "Brightness", L = which "LED"
// Loop until ledRed faded down to zero brightness:
for (int B = 255; B >= 1; B--) {
// set the PWM brightness of led:
analogWrite(L, B);
// change the brightness for next time through the loop:
B = B - fadeAmount;
// Verify potentiometer reading
checkPot();
// wait for "DelayTime" milliseconds to see the dimming effect
delay(DelayTime);
}
}
The CheckPot function just takes a reading from potentiometer and uses it to adjust the DelayTime, which effectively speeds up or slows down the entire effect.
And, in case it helps, a small example of how I'm using FadeUp & FadeDown within void Loop() —
FadeDown(brightnessBlue, ledBlue); //ledBlue DOWN
FadeUp(brightnessRed, ledRed); //ledRed UP
FadeDown(brightness2Red, led2Red); //led2Red DOWN
FadeUp(brightness2Blue, led2Blue); //led2Blue UP
FadeDown(brightnessRed, ledRed); //ledRed DOWN
FadeUp(brightnessRed, ledRed); //ledRed UP
Let me know if you need more info.
Thanks in advance!