Okay! I managed to find a pretty good example on how to turn on/off the LED using set times. Great! This is a very important step for me.
I was able to wire up the Arduino with the LED and RTC module successfully.
My next step I'm trying to tackle is getting this LED to dim accordingly. I guess the best bet is to have the LED dim gradually until 11:00AM (a time I consider to be when there should be the most light) and have it stay on at brightness level 255 until 3:00PM. At that point, I'd like for it to gradually dim until 7:00PM and have it stay off until 6:00AM, every single day.
What is the best way to go about this?
Below is the code I'm using:
#include <TimeLib.h>
#include <TimeAlarms.h>
#include <Wire.h>
#include <DS1307RTC.h> // a basic DS1307 library that returns time as a time_t
const int led = 9;
void setup() {
// prepare pin as output
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
Serial.begin(9600);
// wait for Arduino Serial Monitor
while (!Serial) ;
// get and set the time from the RTC
setSyncProvider(RTC.get);
if (timeStatus() != timeSet)
Serial.println("Unable to sync with the RTC");
else
Serial.println("RTC has set the system time");
// To test your project, we can set the time manually by uncommenting bottom line
//setTime(8,29,0,1,1,11); // set time to Saturday 8:29:00am Jan 1 2011
// create the alarms, to trigger functions at specific times
Alarm.alarmRepeat(3,35,0,MorningAlarm); // 9:00am every day
Alarm.alarmRepeat(3,34,0,EveningAlarm); // 19:00 -> 7:00pm every day
}
void loop() {
digitalClockDisplay();
// wait one second between each clock display in serial monitor
Alarm.delay(1000);
}
// functions to be called when an alarm triggers
void MorningAlarm() {
// write here the task to perform every morning
Serial.println("Turn light off");
digitalWrite(led, LOW);
}
void EveningAlarm() {
// write here the task to perform every evening
Serial.println("Turn light on");
digitalWrite(led, HIGH);
}
void digitalClockDisplay() {
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.println();
}
void printDigits(int digits) {
Serial.print(":");
if (digits < 10)
Serial.print('0');
Serial.print(digits);
}