I am Having trouble with two things. First of all, I'm trying to make a basic clock which displays time (from Datetime library [Arduino Playground - DateTime]), I've looked at other threads and they have helped me a lot.
Problem One:
on the DateTime.makeTime(s, m, h, d, m, y) the date displays incorrectly when used with DateTimeStrings.
(Text value of date is wrong, numerical value is correct)
ie. (0, 15, 11, 21, 11, 9) is 11/21/2009 but ends up as Sunday December 21
Problem 2
There is a way to abbreviate the text month and day of the week. How can i do that?
ie. November -> Nov Saturday -> Sat
#include <LiquidCrystal.h>
#include <DateTimeStrings.h>
#include <DateTime.h>
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
void setup(){
DateTime.sync(DateTime.makeTime(0, 15, 11, 21, 11, 9)); //Problem 1
lcd.begin(16,2);
}
void loop(){
if(DateTime.available()) {
unsigned long prevtime = DateTime.now();
while( prevtime == DateTime.now() ) // wait for the second to rollover
;
DateTime.available(); //refresh the Date and time properties
digitalClockDisplay( ); // update digital clock
}
}
void printDigits(byte digits){
// utility function for digital clock display: prints preceding colon and leading 0
lcd.print(":");
if(digits < 10)
lcd.print('0');
lcd.print(digits,DEC);
}
void digitalClockDisplay(){
lcd.home();
// digital clock display of current time
lcd.print(DateTime.Hour,DEC);
printDigits(DateTime.Minute);
lcd.setCursor(0,1);
lcd.print(DateTimeStrings.dayStr(DateTime.DayofWeek)); //Also part of Problem 1
lcd.print(" ");
lcd.print(DateTimeStrings.monthStr(DateTime.Month)); //How to Shorten?
lcd.print(" ");
lcd.print(DateTime.Day,DEC);
}
time_t makeTime(byte sec, byte min, byte hour, byte day, byte month, int year );
returns time_t from time components, note that year here is full four digit year.
So, "11, 21, 9" is NOT the 21st of November, 2009. It's quite a bit in the past.
Also from the documentation:
char* monthStr(byte month);
If you call it like this:
char *theMonth = monthStr(DateTime.Month());
you can then:
theMonth[3] = '\0';
The variable theMonth would then print out as Nov. You can do the same with the date.
Thank you,
I changed the date so that datetimestring would read it correctly, but..
will DateTime calculate correctly? I placed in 10 so that it would read November but will the ending day of the month be thought of as October's ending day?
i still cannot get the abbreviations to work. i had to change the code a bit to make it valid. Even when it was valid i got a wierd symbol on the lcd screen.
From a noob point of view: theMonth[3] = '\0'; seems like its only going to display 3 letters for ALL months. Anyways to make exceptions for months like sept.
heres the current Code
#include <LiquidCrystal.h>
#include <DateTimeStrings.h>
#include <DateTime.h>
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
char *theMonth = DateTimeStrings.monthStr(DateTime.Month);
void setup(){
DateTime.sync(DateTime.makeTime(0, 15, 11, 21, 10, 2009));
lcd.begin(16,2);
}
void loop(){
if(DateTime.available()) {
unsigned long prevtime = DateTime.now();
while( prevtime == DateTime.now() ) // wait for the second to rollover
;
DateTime.available(); //refresh the Date and time properties
digitalClockDisplay( ); // update digital clock
}
}
void printDigits(byte digits){
// utility function for digital clock display: prints preceding colon and leading 0
lcd.print(":");
if(digits < 10)
lcd.print('0');
lcd.print(digits,DEC);
}
void digitalClockDisplay(){
lcd.home();
// digital clock display of current time
lcd.print(DateTime.Hour,DEC);
printDigits(DateTime.Minute);
lcd.setCursor(0,1);
lcd.print(DateTimeStrings.dayStr(DateTime.DayofWeek));
lcd.print(" ");
lcd.print(theMonth[3] = '\0');
lcd.print(" ");
lcd.print(DateTime.Day,DEC);
}
You can configure the library to use short day and month strings.
Open the dateTimeStrings.cpp file in a text editor and change:
// uncomment one of these month and day defines as appropriate for your application
#define dt_LONG_MONTH_STRINGS true
#define dt_LONG_DAY_STRINGS true
//#define dt_SHORT_DAY_STRINGS
//#define dt_SHORT_MONTH_STRINGS
To
// uncomment one of these month and day defines as appropriate for your application
//#define dt_LONG_MONTH_STRINGS true
//#define dt_LONG_DAY_STRINGS true
#define dt_SHORT_DAY_STRINGS
#define dt_SHORT_MONTH_STRINGS
Change your sketch back to:
lcd.print(DateTimeStrings.monthStr(DateTime.Month));
after recompiling you should see short day and month strings