Can you help? Looking for RTC LED Dim On/Dim Off code.

Hello,

I am searching for a code that will allow me to dim an LED on over 15minutes then dim off over 15 minutes, then turn off for one hour, and then repeat the exact same changes until I turn the arduino and LED off. I have searched on the arduino forum, bildr and other sites but I'm having a difficult time finding something to start with that is simplified.

I have an Arduino MEGA 2560 and an RTC DS1307. (SparkFun Real Time Clock Module - BOB-12708 - SparkFun Electronics)

I have already set the clock on the RTC and have used it in the past.

If someone could point me in the right direction I would greatly appreciate it - even if just a link to get started on the right code.

What I have found on line thus far seems to be for longer periods of time (ie: controls for sunrise and sunset). These parameters are much greater than what I need.

Dawn

What I have found on line thus far seems to be for longer periods of time (ie: controls for sunrise and sunset). These parameters are much greater than what I need.

Changing the interval should be trivial.

Think about what is involved. You have a time that fading is to start. You have a time that fading is to end. You have some number of steps to fade up to, or down to. That defines the interval between steps.

Knowing the start time, the current step, and the time until the next step, you know whether it is time to step, or not. If it isn't, there is nothing to do. If it is, you reset the last step time, and perform the step.

unsigned long startTime = 0;
const unsigned long fadeUpInterval = 15UL * 60UL * 1000UL;  // 15 minutes
const unsigned long fadeDownInterval = 15UL * 60UL * 1000UL;  // 15 minutes
const unsigned long pauseInterval = 60UL * 60UL * 1000UL;  // 1 hour (60 minutes)

void loop() {
    unsigned long currentTime = millis();
    unsigned long interval = currentTime - startTime;

    if (interval < fadeUpInterval) {
        // In the fade-up interval
        analogWrite(LEDPin, 255 * interval / fadeUpInterval);
    } else if (interval < fadeUpInterval+fadeDownInterval) {
        // In the fade-down interval
        analogWrite(LEDPin, 255 - (255 * (interval-fadeUpInterval) / fadeDownInterval);
    } else if (interval >= fadeUpInterval+fadeDownInterval+pauseInterval) {
        // Done with the pause interval
        startTime = currentTime;
    } 
}

If the purpose of getting the time from the RTC, is to syncronize to real time, for example, start dimming at precisely 4:00 and then 5:30 and then 7:00, etc., then you need to set up some kind of wait or synch to RTC time before you run John's code above. Otherwise, no problem.