/*
*// time repeat alarms to control led
*
*/
#include <RTClib.h>
#include <TimeLib.h>
#include <TimeAlarms.h>
#include <Wire.h>
#include <DS3231.h> // a basic DS3231 library that returns time as a time_t
RTC_DS3231 rtc;
const int led = 4 //Sets pin 4 as led
;
void setup() {
Serial.begin(9600);
// wait for Arduino Serial Monitor
while (!Serial) ;
setSyncProvider(getExternalTime()); // the function to get the time from the RTC
if (timeStatus()!= timeSet)
Serial.println("Unable to sync with the RTC");
else
Serial.println("RTC has set the system time");
// create the alarms, to trigger functions at specific times
Alarm.alarmRepeat(5,30,0,MorningAlarm); // 5:30am every day
Alarm.alarmRepeat(21,30,0,EveningAlarm); // 21:30 -> 9:30 pm 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 EveningAlarm() {
// write here the task to perform every morning
Serial.println("Tturn light on");
digitalWrite(led, HIGH);
}
void MorningAlarm() {
// write here the task to perform every evening
Serial.println("Turn light off");
digitalWrite(led, LOW);