Greetings,
I am trying to make an alarm clock that triggers an event at a different time each 'day' for a predetermined number of days*. I have a DS1307 RTC connected to a NANO and can read the time correctly but I am having trouble comparing the RTC time and my times that I have saved in two arrays.
Basically i want something like this for example:
At 06;30 on day 1 perform function (blink led in this example)
At 06;35 on day 2 perform function (blink led in this example)
At 06;40 on day 3 perform function (blink led in this example)
At 06;45 on day 4 perform function (blink led in this example)
At 07;21 on day 5 perform function (blink led in this example)
end
P.s. I realize my code isn't waiting days but for testing i obviously want the times to be close together in the same day. the blinking LED will be replaced with a function that moves a servo for 11 hours so that.
Any help would be greatly appreciated.
thanks
#include "RTClib.h"
RTC_DS1307 rtc;
const int ledPin = 3;
///////////////////////////////////
// alarm times defined here
// eg first alarm @hours[0], minutes[0] = 17:59
// second alarm @hours[1], minutes[1] = 18:00
int hours[] = {17,18,18,18,18,18};
int minutes[] = {59,0,1,3,5,7};
int hour_;
int minute_;
void setup () {
pinMode(ledPin, OUTPUT);
while (!Serial);
Serial.begin(57600);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
}
// following line sets the RTC to the date & time this sketch was compiled
// rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
void loop () {
DateTime now = rtc.now();
Serial.print(now.hour(), DEC); // debug print
Serial.print(':');
Serial.println(now.minute(), DEC);
hour_ = now.hour(); // store current hour as integer
minute_ = now.minute(); // store current minute as integer
Serial.print(hour_); // debug print
Serial.print(':');
Serial.println(minute_);
for (int day_count = 1;day_count <= 7; day_count++)
{
Serial.print("DAY COUNT: ");
Serial.println(day_count);
if (hour_== hours[day_count])
{
if(minute_== minutes[day_count])
{
Serial.println("...................");
Serial.println("the time is now!");
digitalWrite(ledPin, HIGH);
delay(1000); // debug deay short for testing, real function will take ~11 hours.
digitalWrite(ledPin, LOW);
}
}
}
}