hi,
I am new to arduino and wanted to make an alarm clock with arduino duemilanove. I have read through some examples and posts in the forum. I found out that I just need to change the serial.print to lcd.print in datetime example. I tried and it's not working. May I know why? I connected my LCD according to LiquidCrystal example in arduino website
#include <DateTime.h>
#include <DateTimeStrings.h>
#include <LiquidCrystal.h>
#define TIME_MSG_LEN 11 // time sync to PC is HEADER and unix time_t as ten ascii digits
#define TIME_HEADER 255 // Header tag for serial time sync message
const int numRows = 2;
const int numCols = 16;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup(){
Serial.begin(19200);
}
void loop(){
getPCtime(); // try to get time sync from pc
if(DateTime.available()) { // update clocks if time has been synced
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
// send our time to an app listening on the serial port
lcd.print( TIME_HEADER,BYTE); // this is the header for the current time
lcd.println(DateTime.now());
}
}
void getPCtime() {
// if time available from serial port, sync the DateTime library
while(Serial.available() >= TIME_MSG_LEN ){ // time message
if( Serial.read() == TIME_HEADER ) {
time_t pctime = 0;
for(int i=0; i < TIME_MSG_LEN -1; i++){
char c= Serial.read();
if( c >= '0' && c <= '9')
pctime = (10 * pctime) + (c - '0') ; // convert digits to a number
}
DateTime.sync(pctime); // Sync DateTime clock to the time received on the serial port
}
}
}
void digitalClockDisplay(){
// digital clock display of current time
lcd.print(DateTime.Hour,DEC);
printDigits(DateTime.Minute);
printDigits(DateTime.Second);
}
void printDigits(byte digits){
// utility function for digital clock display: prints colon and leading 0
lcd.print(":");
if(digits < 10)
lcd.print('0');
lcd.print(digits,DEC);
}