I am building a timer controlled latching relais with the use of a Arduino Trinket, a DS1307 shield and a latching relais board.
I have some problems getting my code to work. Since I habe no serial adapter for the trinket all debugging is done via the onboard LED
So far I am working on a sketch which should set the time of the RTC during first setup to the current computer time, with some considerations like timezones and daylight savings time.
However, after I set the DS1307 clock to a specified value (not using the builtin __DATE__ and __TIME__ macros) and get the current time via the RTC.now() function, the values do not match (even closely) what I have used in order to set the time.
RTC.now().month() seems to return the day value (in my example 25)
RTC.now().day() seems to return the month value (in my example 19)
RTC.now().year() seems to be completely unrelated (211).
tell() is a helper function which blinks the led (shaving off values > 2000, 1000, 500, 200)
yes() and no() are helper functions for simple state output.
My Sketch:
Code: Select all
#include <TinyWireM.h>
#include <TinyRTClib.h>
#define LED 1
RTC_DS1307 RTC;
void setup() {
no();
delay(2000);
DateTime now;
RTC.begin();
//now = DateTime(__DATE__, __TIME__);
now = DateTime(2014, 3, 25, 14, 19, 0);
RTC.adjust(now);
// blink LED with the months I used to create the DateTime object
tell(now.month());
delay(2000);
// blink the LED with the months from the TinyRTClib library
tell(RTC.now().month());
}
void tell(uint8_t count) {
if(count < 2030) {
if(count > 2000) {
digitalWrite(LED, HIGH);
delay(15000);
digitalWrite(LED, LOW);
count -= 2000;
delay(1000);
}
if(count > 1000) {
digitalWrite(LED, HIGH);
delay(10000);
digitalWrite(LED, LOW);
count -= 1000;
delay(1000);
}
if(count > 500) {
digitalWrite(LED, HIGH);
delay(5000);
digitalWrite(LED, LOW);
count -= 500;
delay(1000);
}
if(count > 200) {
digitalWrite(LED, HIGH);
delay(2500);
digitalWrite(LED, LOW);
count -= 200;
delay(1000);
}
if(count > 100) {
digitalWrite(LED, HIGH);
delay(1000);
digitalWrite(LED, LOW);
count -= 100;
delay(1000);
}
while(count > 0) {
digitalWrite(LED, HIGH);
delay(300);
digitalWrite(LED, LOW);
count--;
delay(300);
}
}
}
void yes() {
digitalWrite(LED, HIGH);
delay(3000);
digitalWrite(LED, LOW);
}
void no() {
for(uint8_t i = 0; i < 10; i++) {
if(i > 0) delay(150);
digitalWrite(LED, HIGH);
delay(150);
digitalWrite(LED, LOW);
}
}
void loop() {
}
I hope to get some hints as to what could be wrong...