Blinking LED quits working.

This is a simple code which can probably be done a better way. The problem I am having is after some time the LED quites blinking, can anyone tell me why or maybe a better way to do this. The led is just to let me know the clock is working as it blink once per minute. Thanks

#include <Wire.h>
#include "RTClib.h"
#define clockAlarm 5 // Relay Output
#define ledIndicator 7 // LED Output
int hour1;
int minute1;
int year1;
int month1;
int day1;
int second1;
int runOnce = 0;
int ledEarlier =0;
RTC_DS1307 RTC;

void setup ()
{
Wire.begin();
RTC.begin();
pinMode (clockAlarm, OUTPUT); // set output 5
pinMode ( ledIndicator, OUTPUT); // set output 7
}

void loop () {
DateTime now = RTC.now();
hour1 = (now.hour());
minute1 = (now.minute());
second1 = (now.second());

if (now.minute() > ledEarlier)
{
ledEarlier = now.minute();
digitalWrite(ledIndicator, HIGH); // turn on led
delay(100);
digitalWrite(ledIndicator, LOW); // turn off led
}
else if (hour1 == 6 && minute1 == 55)
{
if(runOnce == 0)
{
digitalWrite(clockAlarm, HIGH); // activate alarm relay
delay(3000);
digitalWrite(clockAlarm, LOW); // activate alarm relay
runOnce = 1;
}
}
else
{
runOnce = 0;
}
delay(1000);
}

Pabble:
if (now.minute() > ledEarlier)
{
ledEarlier = now.minute();

The problem is this part. After minute rolls over, it's not going to be bigger than ledEarlier anymore.

Say you start the sketch and the led blinks at 1:59. One minute later, it's 2:00. Now minute is 0 and ledEarlier is 59. So the if statement is now false all the time since minute will never be more than 59.

Thanks, that makes perfect sense, that would explain it working for quite awhile before quiting sometimes. That never occurred to me, duh :slight_smile:

Since time only marches forward and as of yet no one knows how to make it go backwards, you could instead ask:

if (now.minute() != ledEarlier)
{

Since ledEarlier is always in the past, then anytime now is different, it must also be greater.

Very good thanks, I will try that. BTW I am new to this stuff but trying to learn, I will have to remember to use not equal to in the future.