I'm still just messing around with this tinyRTC DS1307 learning how it does this and that. My question is: Is it ever permitted to use a "IF" statement like the one below with this RTC library? I figured I would experiment with just seeing if I could use the timer to turn on a LED at a specific hour, minute and second. It verifies, uploads fine. But, doesn't work. Any hint at some further reading is appreciated!
As a side note- I know this DS1307 is not super accurate and in fact over two weeks it gained 8 minutes! Hooray
Just experimenting for future ideas.
Code:
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 rtc;
const int LED = 12;
void setup () {
// Configure pins A2 and A3 to provide power and ground
pinMode(A3, OUTPUT);
pinMode(A2, OUTPUT);
digitalWrite(A3, HIGH); // provides +5V
digitalWrite(A2, LOW); // provides GND
Serial.begin(57600);
#ifdef AVR
Wire.begin();
#else
Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino Due
#endif
rtc.begin();
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
}
}
void loop () {
DateTime now = rtc.now();
delay(3000);
if ((now.hour()=='17')&&(now.minute()=='42')&&(now.second()=='11'))
{pinMode(LED, OUTPUT);
digitalWrite(LED, HIGH);
delay(10000);
digitalWrite(LED, LOW);
delay(5000);}
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
delay(5000);
}
Just experimenting for future ideas.