I am doing an aquarium light sunrise/sunset. Till now programming wise I only did the sunrise. After running the code the light starts to rise up fine, than at full brightness, it turns off. I want to keep it on after it reaches the 100% pwm and than starts decreasing when it's time to get off. Any help on how to leave the pwm at 100% and than starts to dim when it's time to turn off? I am still new to coding arduino, so explanation need to be for a beginner :P Thanks before hand.
#include <DS3231.h>
//Set Variables
int fadeTime = 15; //Fade Time
int onHour = 12; //Light On Hour
int onMin = 00; //Light On Minute
int offHour = 19; //Light On Hour
int offMin = 00; //Light On Minute
int led = 9; //Set pinout with with PWM
DS3231 rtc(SDA, SCL);
Time t;
void start();
void setup()
{
pinMode(led, OUTPUT);
rtc.begin();
}
void loop()
{
t = rtc.getTime();
// Send Day-of-Week
Serial.print(rtc.getDOWStr());
Serial.print(" ");
// Send date
Serial.print(rtc.getDateStr());
Serial.print(" -- ");
// Send time
Serial.println(rtc.getTimeStr());
if (t.hour == onHour && t.min == onMin) //Check Time
{
start();
}
}
void start()
{
// Fade script
for (int i = 0 ; i <= 255; i++)
{
analogWrite(led, i);
delay(((fadeTime * 60000)/306));
}
}
start
. – Gerben Apr 6 '17 at 18:47