[solved]String not being updated

It prints T:0:0:0, and stopped. It doesn’t updated itself. What is the problem to this string code?

String ss, mm, hh, lcdprint;
  hh = String ("T:") + hrs;
  mm = String (":") + mint; 
  ss = String (":") + sec;  
  lcdprint= hh+mm+ss;
  lcd.setCursor(6, 0);    
  lcd.print(lcdprint);

Don't use Strings, use char arrays:

char szTime[12];
sprintf( szTime, "T:%02d:%02d:%02d", hrs, mint, sec );
lcd.print( szTime );

But your problem is (probably) that hrs, mint, and sec are integers and can't be "added" to Strings... I don't really know, I never used those Strings :). At least that what I can guess from this short code, you don't show how those variables are declared and assigned.

guix:
Don’t use Strings, use char arrays:

char szTime[12];

sprintf( szTime, “T:%02d:%02d:%02d”, hrs, mint, sec );
lcd.print( szTime );




But your problem is (probably) that hrs, mint, and sec are integers and can't be "added" to Strings... I don't really know, I never used those Strings :). At least that what I can guess from this short code, you don't show how those variables are declared and assigned.

Thanks so much…
meanwhile I wrote this long code to print the time. doesn’t really works perfectly either

  lcd.setCursor(7, 0);    
  lcd.print("0");     
  lcd.setCursor(10, 0);    
  lcd.print("0");  
  lcd.setCursor(13, 0);    
  lcd.print("0");    
    
  lcd.setCursor(6, 0);    
  lcd.print("T");     
  
  if(hrs<10){
  lcd.setCursor(8, 0);    
  lcd.print(hrs);}
  else{
  lcd.setCursor(7, 0);    
  lcd.print(hrs);
  }
  
  lcd.setCursor(9, 0);    
  lcd.print(":");  
  
  if(mint<10){
  lcd.setCursor(11, 0);    
  lcd.print(mint);}
  else{
  lcd.setCursor(10, 0);    
  lcd.print(mint);
  }  
  
  lcd.setCursor(12, 0);    
  lcd.print(":");  
  
  if(sec<10){
  lcd.setCursor(14, 0);    
  lcd.print(sec);}
  else{
  lcd.setCursor(13, 0);    
  lcd.print(sec);
  }

works perfectly, thanks again. never seen this function sprintf() in the reference page.

guix:
Don't use Strings, use char arrays:

char szTime[12];

sprintf( szTime, "T:%02d:%02d:%02d", hrs, mint, sec );
lcd.print( szTime );




But your problem is (probably) that hrs, mint, and sec are integers and can't be "added" to Strings... I don't really know, I never used those Strings :). At least that what I can guess from this short code, you don't show how those variables are declared and assigned.

NP :slight_smile:

Here you have list of functions you can use: avr-libc: Modules

And refer to this site for some examples: Reference - C++ Reference

guix:
NP :slight_smile:

Here you have list of functions you can use: avr-libc: Modules

And refer to this site for some examples: Reference - C++ Reference

Thanks a lot, I have bookmarked these pages and will read them through later. One more simple question: Do I need to add #include <stdio.h> to the Arduino sketch in order to use those functions from stdio.h?

No, those are standard libraries and are automatically included when you compile the sketch.