Why cant a variable be set to an RTC date?
Moderators: adafruit_support_bill, adafruit

Why cant a variable be set to an RTC date?

by Spiney on Tue Oct 23, 2012 12:10 pm

Got to be doing something stupid?
Here is a simple program that calls up DateTime now, prints now.day correctly and then attempts to set a volatile variable (dy) and a variable (day) to now.day and then prints the two variables. Both are printed as 10. Finally now.day is printed again for proof.
The output is
23 today's date correct.
10 error
10 error
23 Proof that now.day is not corrupted.

I hope an expert can solve this in microseconds for me.
Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;

volatile int dy=0;
int day=0;
void setup()
{
    Serial.begin(9600);
    Wire.begin();
    RTC.begin();
    delay(100);
}

void loop()
{
    DateTime now = RTC.now();

    Serial.println(now.day(), DEC);
    dy=(now.day(), DEC); 
    Serial.print(dy);
    Serial.println();
    day=(now.day(), DEC);
    Serial.println(day);
    Serial.println(now.day(), DEC);
    Serial.println();
   delay(2000);
}
Spiney
 
Posts: 165
Joined: Mon Jul 09, 2012 6:35 am

Re: Why cant a variable be set to an RTC date?

by adafruit_support_bill on Tue Oct 23, 2012 12:26 pm

Code: Select all | TOGGLE FULL SIZE
    dy=(now.day(), DEC); 

I think what you want is just:
Code: Select all | TOGGLE FULL SIZE
    dy=now.day(); 
User avatar
adafruit_support_bill
 
Posts: 30866
Joined: Sat Feb 07, 2009 10:11 am

Re: Why cant a variable be set to an RTC date?

by Spiney on Tue Oct 23, 2012 12:33 pm

Great Thank you. It works. All my Interrupt problems may be over!
Regards
Spiney
 
Posts: 165
Joined: Mon Jul 09, 2012 6:35 am