Im actually trying to fade in an LED driver with a step every 6 minutes. Its steps up fine but sometimes the LED doesnt fully turn off or doesnt stay in the correct PWM level between steps.
Here is a sample of my fade in:
//Whites Sunrise begins at 9am and fades in every 6 minutes for an hour ( 10 steps ) until fully on
{
if ((hour ==9 )&&( minute==1 ))analogWrite (led_white_pin, 25);
if ((hour ==9 )&&( minute==6 ))analogWrite (led_white_pin, 50);
if ((hour ==9 )&&( minute==12 ))analogWrite (led_white_pin, 75);
if ((hour ==9 )&&( minute==18 ))analogWrite (led_white_pin, 100);
if ((hour ==9 )&&( minute==24 ))analogWrite (led_white_pin, 125);
if ((hour ==9 )&&( minute==30 ))analogWrite (led_white_pin, 150);
if ((hour ==9 )&&( minute==36 ))analogWrite (led_white_pin, 175);
if ((hour ==9 )&&( minute==42 ))analogWrite (led_white_pin, 200);
if ((hour ==9 )&&( minute==48 ))analogWrite (led_white_pin, 225);
if ((hour ==9 )&&( minute==54 ))analogWrite (led_white_pin, 255);
}
Is there a more simple way to say " at 9am fade in from 0 to 255 over 1 hour then stay in that final state until being faded out at 10pm?"
Ive just been looking at the above code and here it is in my sketch:
//Whites Sunrise begins at 9am and fades in every 6 minutes for an hour ( 10 steps ) until fully on
{
if (hour ==9 ) analogWrite (led_white_pin, map(minute, 0,59,0,255) );
}
//Whites Sunset begins at 8pm and fades out every 6 minutes for an hour ( 10 steps ) until fully off
{
if (hour ==20 ) analogWrite (led_white_pin, map(minute, 0,59,255,0) );
else analogWrite (led_white_pin, 0);
}
But i want the lights to fade in from 9am and then stay on full until 8pm when they then fade out. But wont the else analogWrite (led_white_pin, 0); turn off the lights inbetween these times as the program is continually run though by the processor??
You can remove the else statements if you want the light to stay on.
Also, you may want to add a check in setup to see if the light should be fully on when the sketch starts.
Ahh now i follow. So in theory if it does'nt receive any other commands it will stay in those states until another command tells it to do something else?
What do you mean about the 'Check' in the setup portion of the sketch?
Yes, an analog output will maintain the last value written.
If you power up or reset Arduino at a time after your fade-up (10am) and before the start of your fade-out (8pm), the light will be off when it should be on. If you check to see if you are within this period you can correctly set the light state.