I am making a project to have a set of LEDs fade in over a period of 6 hours, and then to fade back out again during a period of 6 hours. with a 12 hour period where they are off, then the cycle starts again.
I messed with the fading led sketch and got a bit of help from a programmer or 2 that i know to get the thing refined and to get the correct delay setting to make it work over the time period i desired.
for those who want to know its a prototype for a LED grow light setup i am making to give my plants a bit of extra light during the dark months over winter (i live in Norway in the polar circle, and we get 2 months of dark with no sun at all),so using some ultrabright LEDs i hope to help them out until the spring.
here is the code i have at present (running on 3 chip setups: one a lillipad bootloader on internal clock, one with dec bootloader on a 16 MHz crystal on a breadboard, and one with a 16 MHz osc on a Dcore board {thnx John Ryan})
// Daytime LED
int value = 0; // variable to keep the actual value
int ledpin1 = 11; // light connected to digital PWM pins 3 - 11
int ledpin2 = 10;
int ledpin3 = 9;
int ledpin4 = 6;
int ledpin5 = 5;
int ledpin6 = 3;
void setup()
{
// nothing for setup
}
#define set_pins(value) analogWrite(ledpin1, value);analogWrite(ledpin2, value);analogWrite(ledpin3, value);analogWrite(ledpin4, value); analogWrite(ledpin5, value); analogWrite(ledpin6, value); delay(84705);
void loop()
{
for(;;) {
for(value = 0 ; value <= 255; value+=1) { // fade in (from min to max in 255 steps)
set_pins(value);
}
for(value = 255; value >=0; value-=1) { // fade out (from max to min in 255 steps)
set_pins(value);
}
for(value = 0 ; value <= 255; value+=1) {
set_pins(0);
}
for(value = 255; value >=0; value-=1) { // fade out (from max to min in 255 steps)
set_pins(0);
}
}
}
am currently running this code (cleaned up by a friend from the old setup i hashed up from the fading led sketch) on all 3 to see if the problem is hardware related.
You see the problem is that at some point during the cycle the LEDs fail to dim, or are in the dimming part of the cycle and go to full brightness, or are in the fading in part and just speed up to full, and then stay like that.
when i ran the prog with a 50 ms delay it ran fine for well over the time i was running the realtime one. no problems for what i could see, it faded in to full, faded out and was off for the same amount of time.
the LEDs are ultrabright ones of 3.2V or 3.5V (blue and white, i would like to have red but don't have any), not sure what resistors to use so any suggestion would be good.
And they are using all the default pwm pins (3,5,6,9,10,11)
i hope this is enough info and would really appreciate any input from those of u who know more than i do about programming and the hardware.
thanx
Bng.