Hola tengo un problema, tengo un LCD que enseña la hora, pero trato de sincronizar con un texto serial en el Formato T123456 osea THHMMSS
mi problema es que puedo hacer un enquire y me envia la info correcta pero cuando quiero actualizarlo no lo hace
[edit] http://www.arduino.cc/en/Tutorial/LiquidCrystal
*/
// include the library code:
#include <LiquidCrystal.h>
#include <Time.h>
// to set the time bytes
int seconds_ones; // Initialise values for tens and ones units of h,m,s
int seconds_tens;
int minutes_ones;
int minutes_tens; //
int hours_ones;
int hours_tens;
//volatile unsigned char tick;
// char timeString[7]; // create a string to hold the time value when it's read
char seconds = 0;
char minutes = 58; // Inititialise actual values for h,m,s
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 timeString[]= "T232323";
//int rxString = 0 ;
//int inByte = 0 ; // incoming serial byte
//char inString[7];
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(" LCD DISPLAY ");
}
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);
memset(timeString,'\0',7); // initialize that string to all NULL characters
// Upadte time automatically every sec and Display on LCD
get_serial_rx(); // look for incomming data
delay(1000);
seconds ++ ;
display_time (); // send the time to the LCD to be displayed
}
void display_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;}
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);
}
//// Process a line of text from the serial port.
//void SerialEvent(Serial p) {
// inString[] = (port.readString());
//print("received: " + input);
//}
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
}
AQUI esta mi problema cuando trato de actualizar
void Update_time() {
hours_tens = timeString[1];
hours_ones = timeString[2];
minutes_tens = timeString[3];
minutes_ones = timeString[4];
seconds_tens = timeString[5];
seconds_ones = timeString[6];
}
void get_serial_rx() {
char timeString[7] = {0}; //change to appropriate value
int incount = 0;
if ( Serial.available()) {
while (Serial.available()) {
timeString[incount++] = Serial.read();
}
timeString[incount] = '\0'; // puts an end on the string
}
// test for 7 char "T123456" sample of HHMMSS
if ((timeString[0]) == T){ // Prepare to Set the time
Update_time();
// Serial.flush(); // clear the buffer
}
// if(timeString[0] != '\0'){
if(timeString[0] ==D){
Serial.println(timeString);
// //sendCommand(timeString);
timeString[0]= '\0';
}
//========================================================
if ((timeString[0]) == t){ // to inquire the time
Serialtime_out();
// Serial.flush(); // clear the buffer
}
Serial.flush(); // clear the buffer
}[/edit]
gracias por su ayuda, soy nuevo en C programming es posible que me falte algun detalle