hey guys
i have made a time clock test
it uses the time and liquid crystal libarys
i thinks there is a few bugs in it.
can you please test this out on your display.
requires time lib and prosessing for serial connection as of it being based on TimeSerial.pde
bugs i think there is are the waiting for sync message
thanks ryan
/*
- TimeSerial.pde
- example code illustrating Time library set through serial port messages.
- Messages consist of the letter T followed by ten digit time (as seconds since Jan 1 1970)
- you can send the text on the next line using Serial Monitor to set the clock to noon Jan 1 2010
T1262347200- A Processing example sketch to automatically send the messages is inclided in the download
/
/
*Modified To Add Liquid Crystal Support
*By Ryan Walmsley
*Ryanteck.co.uk
*/#include <Time.h>
#include <LiquidCrystal.h>LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#define TIME_MSG_LEN 11 // time sync to PC is HEADER followed by unix time_t as ten ascii digits
#define TIME_HEADER 'T' // Header tag for serial time sync message
#define TIME_REQUEST 7 // ASCII bell character requests a time sync messagevoid setup() {
Serial.begin(9600);
setSyncProvider( requestSync); //set function to call when sync required
// set up the LCD's number of rows and columns:
lcd.begin(16, 2);
lcd.println("Waiting for sync");
}void loop(){
if(Serial.available() )
{
processSyncMessage();
}
if(timeStatus()!= timeNotSet)
{
digitalWrite(13,timeStatus() == timeSet); // on if synced, off if needs refresh
lcd.setCursor(0, 0);
digitalClockDisplay();
lcd.setCursor(0, 1);
digitaldateDisplay();}
delay(1000);
}void digitalClockDisplay(){
// digital clock display of the time
lcd.print("Time: ");
lcd.print(hour());
lcd.print(":");
lcd.print(minute());
lcd.print(":");
lcd.print(second());
lcd.print(" ");
lcd.print(" ");
}
void digitaldateDisplay(){
// display date on line 1
lcd.print("Date:");
lcd.print(" ");
lcd.print(day());
lcd.print(" ");
lcd.print(month());
lcd.print(" ");
lcd.print(year());
lcd.println();
}void printDigits(int digits){
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}void processSyncMessage() {
// if time sync available from serial port, update time and return true
while(Serial.available() >= TIME_MSG_LEN ){ // time message consists of a header and ten ascii digits
char c = Serial.read() ;
Serial.print(c);
if( c == TIME_HEADER ) {
time_t pctime = 0;
for(int i=0; i < TIME_MSG_LEN -1; i++){
c = Serial.read();
if( c >= '0' && c <= '9'){
pctime = (10 * pctime) + (c - '0') ; // convert digits to a number
}
}
setTime(pctime); // Sync Arduino clock to the time received on the serial port
}
}
}time_t requestSync()
{
Serial.print(TIME_REQUEST,BYTE);
return 0; // the time will be sent later in response to serial mesg
}