Why cant a variable be set to an RTC date?

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
spiney
 
Posts: 214
Joined: Mon Jul 09, 2012 6:35 am

Why cant a variable be set to an RTC date?

Post by spiney »

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

#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); 
}

User avatar
adafruit_support_bill
 
Posts: 88091
Joined: Sat Feb 07, 2009 10:11 am

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

Post by adafruit_support_bill »

Code: Select all

    dy=(now.day(), DEC);  
I think what you want is just:

Code: Select all

    dy=now.day();  

User avatar
spiney
 
Posts: 214
Joined: Mon Jul 09, 2012 6:35 am

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

Post by spiney »

Great Thank you. It works. All my Interrupt problems may be over!
Regards

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”