Go Down

Topic: Fade an LED in and out based on Real Time Clock reading (Read 816 times) previous topic - next topic

Testingpurposes

Hi All,

I need some fuel for an idea I'm sure has been done - but I am unable to find good examples of.

I have a PWM dimmed LED driver that I would like to control using an arduino and a RTC.  I have a working fade script, but would like to make the duty cycle specific to the RTC value.

I would like to fade on from 0-255 over the course of 2 hours - remain at 255 for 2 hours - then fade back down to 0 over 2 hours and remain off for 6 hours.

If the arduino is shut off mid way through a fade, I would like it to be able to pick up where it should be once turned on.  IE if it is shut off at a duty cycle of 150 for 2 minutes then turned back on I would like it to pick up at 155 or whatever it would be.  This is the part I'm having trouble with.



I'm not looking for spoon fed code - but am interested in ideas of how this might work.   I understand that it would be simple to initiate a fade sequence at a particular time, but I'm not sure how to keep the fading in pace with the RTC.

Sincere thanks for any brain food,
Rob


PaulRB

If the arduino is shut off mid way through a fade, I would like it to be able to pick up where it should be once turned on.  IE if it is shut off at a duty cycle of 150 for 2 minutes then turned back on I would like it to pick up at 155 or whatever it would be.
No problem. The RTC will have a battery back up, so it won't loose the time when the Arduino is shut off.

So when the Arduino starts up, the first thing the sketch should do is read the RTC and figure out where in the fade up/hold/fade down/off cycle it should be. It can then calculate how many minutes we are into the fade up/down periods, then use map() to convert this to a 0..255 figure for analogWrite(). Then the sketch waits a minute and repeats the same thing.

Paul

Go Up