Hi all. I'm having a hard time getting my ST7565 to display an accurate date and time. The DS1307 is set to my computer's time, and has been verified with serial.print; however, the bit I'm struggling with is getting the ST7565 to say anything other than 10/10/10 10:10.
How do I use sprintf to make a coherent string that I can display on the screen? The man page is a little cryptic/dense, and I'm beginning to feel like I've been banging my head on a wall for a couple of hours now.
The code I'm using goes something like this:
int rtcYear;
int rtcMonth;
int rtcDay;
...
rtcYear = (now.year(), DEC);
rtcMonth = (now.month(), DEC);
rtcDay = (now.day(), DEC);
sprintf(date,"%i/%i/%i",(int)rtcDay,(int)rtcMonth,(int)rtcYear);
I'm sure that I'm doing something retarded here, but I genuinely don't know what. It all compiles quite happily, so I don't have a clear indicator as to what's causing the problem.
Hmm I have a question: The library DS1307 (of Arduino-0022) doesn't contain .day(), .month(), .year() functions. Have these been added in a later version or is that another DS1307 library than the one supplied with Arduino package??
Please explain what you think this is doing. It isn't, but I'm interested in what you think it is doing.
I was under the impression that it would force the output of calling now.year to be in decimal, which is what the reference documentation suggests.
Either way, having cut out the majority of what I wrote in my previous post, I've noticed just what a titanic spaz I was being.
For the record, I do understand the relationship between DEC and 10, I just didn't understand why it was setting everything to 10. Subsequently, it also defaulted to 10/47/48, which is why I didn't automatically link the two.
However, it works now, and I have learned a lesson (of sorts).
Thanks for pointing out my idiocy - much as I'd ordinarily be railing against it, it was necessary there.
@braindead - the DS1307 library that I'm using is the one referenced here. It's called RTClib; I wasn't sure if it was a hardware foible that was causing the problem, or just me being a berk. It was proven to be the latter.
I was under the impression that it would force the output of calling now.year to be in decimal, which is what the reference documentation suggests.
What reference documentation are you referring to? I think you misread something. The output of now.year() is an integer value. It is stored internally in binary. I don't know what you mean by "force it to be in decimal".
It looks like you changed Serial.print(now.year(), DEC); to rtcYear = (now.year(), DEC); which is meaningless. It makes as much sense as changing digitalWrite(LEDPin, LedVal); to int stuff = (LEDPin, LedVal);
I was under the impression that it would force the output of calling now.year to be in decimal, which is what the reference documentation suggests.
What reference documentation are you referring to? I think you misread something. The output of now.year() is an integer value. It is stored internally in binary. I don't know what you mean by "force it to be in decimal".
It looks like you changed Serial.print(now.year(), DEC); to rtcYear = (now.year(), DEC); which is meaningless. It makes as much sense as changing digitalWrite(LEDPin, LedVal); to int stuff = (LEDPin, LedVal);