Hi I have a problem trying to update my time clock via serial port < the rest of the functions LCD display and time track are working correct but my code does not update the serial time sent, any suggestions
// include the library code:
#include <LiquidCrystal.h>
#include <Time.h>
// to set the time bytes
char timeString[7]; // create a string to hold the time value when it's read
int seconds_ones;
int minutes_ones;
int hours_ones;
int seconds_tens; // Initialise values for tens and ones units of h,m,s
int minutes_tens; // these are the values actually sent to the LEDs
int hours_tens;
//volatile unsigned char tick;
unsigned char seconds = 0;
unsigned char minutes = 58; // Inititialise actual values for h,m,s
unsigned char hours = 23;
int hours_increase = 0;
int mins_increase = 0;
int val = 0; // to adjust the clock
long time = 0;
// try to get serial in out
char incomingByte; // for incoming serial data
char inString[]= "0000000";
int i = 0 ;
int T = 84; // ASCII T
int D = 68; //asccii D
int t = 116; // ascci t
// initialize the library with the numbers of the interface pins
//LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup() {
{
// start serial port at 9600 bps:
Serial.begin(9600);
}
// set up the LCD's number of rows and columns:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print(" MY TIME IS ");
}
void loop() {
i=0; // reset the array index
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 8):
lcd.setCursor(8, 1); // here the time is displayed on the LCD
//this is a polling routine to get MY_time serial out
if ((Serial.available() >0) && (Serial.read() == t)) {
//if(Serial.read() == t) ; // to inquire the time
Serialtime_out();
}
if(Serial.read() == 'T ') { // wait for 7 characters
for (int i=0; i < 7; i++) {
timeString[i] = Serial.read(); // reach each time string character into a character array
}
}
if (timeString[0]=='T') {
hours_tens= (timeString[1]);
hours_ones = (timeString[2]);
minutes_tens = (timeString[3]) ;
minutes_ones = (timeString[4]);
seconds_tens= (timeString[5]);
seconds_ones= (timeString[6]);
}
//// to test that the T123456 was store properly waiting for D to dump
if ((Serial.available() >0) && (Serial.read() == D)){ // to inquire the time
// Serial.print(inString);
// Serial.print(inString[1], BYTE);
// Serial.print(inString[2], BYTE);
// Serial.print(inString[3], BYTE);
// Serial.print(inString[4], BYTE);
// Serial.print(inString[5], BYTE);
// Serial.print(inString[6], BYTE);
//Serial.print(inString[6], BYTE
}
Serial.flush(); // clear the buffer
delay(1000);
seconds ++ ;
My_time (); // 24 hour format keep displayed
// lcd display of time
lcd.print(hours_tens);
lcd.print(hours_ones);
lcd.print(":");
lcd.print(minutes_tens);
lcd.print(minutes_ones);
lcd.print(":");
lcd.print(seconds_tens);
lcd.print(seconds_ones);
}
void My_time () { // Function to display the time
seconds_ones = seconds % 10; // Get the 1's digit of seconds
if (seconds>=10){ // If seconds greater than 10
seconds_tens = seconds / 10;} // Get 10's digit of seconds
else {
seconds_tens = 0;} // Otherwise 10s is 0
// to adjust the more than 60
if (seconds>=60){ // If seconds greater than 10
// seconds_tens = seconds / 10;} // Get 10's digit of seconds
//else {
seconds_ones = 0;
seconds_tens = 0;
seconds = 0 ; // Otherwise 10s is 0
minutes ++ ;} // inc min
// MINUTES
minutes_ones = minutes % 10; // Repeat for minutes
if (minutes>=10){
minutes_tens = minutes / 10 ;}
else {
minutes_tens = 0;}
// to adjust the more than 60
if (minutes>=60){
// minutes_tens = minutes / 10 ;}
// else {
minutes_ones = 0;
minutes_tens = 0;
minutes = 0 ;
hours ++;} // inc hour
// to adjust the 24
hours_ones = hours % 10; // Repeat for seconds
if (hours>=10){
hours_tens = hours / 10 ;}
else {
hours_tens = 0;}
// here is the 24 hours reset
if (hours>=24){
// hours_tens = hours / 10 ;}
// else {
seconds_ones = 0; // reset to cero
seconds_tens = 0;
minutes_ones = 0;
minutes_tens = 0;
hours_ones = 0;
hours_tens = 0;
seconds = 0;
minutes = 0;
hours = 0;}
}
// send out the serial time displayed
void Serialtime_out() {
///// serial output of time
Serial.println("Your Time is"); // send an initial string
Serial.print(hours_tens);
Serial.print(hours_ones);
Serial.print(":");
Serial.print(minutes_tens);
Serial.print(minutes_ones);
Serial.print(":");
Serial.print(seconds_tens);
Serial.print(seconds_ones);
Serial.println(" "); // send an initial string
}