Hi Everybody!
I have my first project on an Uno utilizing the fade function. I have something working but wanted to see if I could take it a little further. To describe what is going on, I have six LED lights set to cycle through fade loops, each with different max/min values.
What I would like to be able to do is have each light running through it's cycle at an independent rate (all six are running at the same time) to give it a more organic look. I've taken a look at a few sketches for fades and running multiple things at once but I don't seem to be able to comprehend it.
A bonus would be if I could have a long form program for the LEDs where I could write out multiple hours of behavior as well as have them shut off when I do not expect people to be there.
Here is the code I was working with...
int led_1 = 3; // the PWM pin the LED is attached to
int led_2 = 5; // the PWM pin the LED is attached to
int led_3 = 6; // the PWM pin the LED is attached to
int led_4 = 9; // the PWM pin the LED is attached to
int led_5 = 10; // the PWM pin the LED is attached to
int led_6 = 11; // the PWM pin the LED is attached to
int brightness_1 = 175; // how bright the LED is
int brightness_2 = 60; // how bright the LED is
int brightness_3 = 120; // how bright the LED is
int brightness_4 = 100; // how bright the LED is
int brightness_5 = 75; // how bright the LED is
int brightness_6 = 200; // how bright the LED is
int fadeAmount_1 = 1; // how many points to fade the LED by
int fadeAmount_2 = 1; // how many points to fade the LED by
int fadeAmount_3 = 1; // how many points to fade the LED by
int fadeAmount_4 = 1; // how many points to fade the LED by
int fadeAmount_5 = 1; // how many points to fade the LED by
int fadeAmount_6 = 1; // how many points to fade the LED by
// the setup routine runs once when you press reset:
void setup() {
// declare pin 9 to be an output:
pinMode(led_1, OUTPUT);
pinMode(led_2, OUTPUT);
pinMode(led_3, OUTPUT);
pinMode(led_4, OUTPUT);
pinMode(led_5, OUTPUT);
pinMode(led_6, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// set the brightness of pin 9:
analogWrite(led_1, brightness_1);
analogWrite(led_2, brightness_2);
analogWrite(led_3, brightness_3);
analogWrite(led_4, brightness_4);
analogWrite(led_5, brightness_5);
analogWrite(led_6, brightness_6);
// change the brightness for next time through the loop:
brightness_1 = brightness_1 + fadeAmount_1;
brightness_2 = brightness_2 + fadeAmount_2;
brightness_3 = brightness_3 + fadeAmount_3;
brightness_4 = brightness_4 + fadeAmount_4;
brightness_5 = brightness_5 + fadeAmount_5;
brightness_6 = brightness_6 + fadeAmount_6;
// reverse the direction of the fading at the ends of the fade:
if (brightness_1 <= 7 || brightness_1 >= 205) {
fadeAmount_1 = -fadeAmount_1;
} if (brightness_2 <= 5 || brightness_2 >= 175) {
fadeAmount_2 = -fadeAmount_2;
} if (brightness_3 <= 10 || brightness_3 >= 180) {
fadeAmount_3 = -fadeAmount_3;
} if (brightness_4 <= 15 || brightness_4 >= 210) {
fadeAmount_4 = -fadeAmount_4;
} if (brightness_5 <= 10 || brightness_5 >= 200) {
fadeAmount_5 = -fadeAmount_5;
} if (brightness_6 <= 20 || brightness_6 >= 240) {
fadeAmount_6 = -fadeAmount_6;
}
// wait for 30 milliseconds to see the dimming effect
delay(90);
}
Any help would be greatly appreciated.