Pages: [1]   Go Down
Author Topic: Showing year as three digits!  (Read 598 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everyone,
This line has caused the year to be shown as 3 digits, (201). Could someone put me out of my misery and show me how to do it. The rest of the line works fine.

chars = sprintf( test, "%02d:%02d:%02d   %02d:%02d:%04d   ", hour(), minute(), second(), day(), month(), year() );

I changed the  %02d to %04d but this made no difference.
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3638
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Looks fine. Post the entire sketch for more help.
Logged

Austin, TX
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6137
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, need to see the whole sketch.  Specifically how test and chars are defined and how you are using them.  Also, what is creating these functions you are getting the data from.
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for your prompt replies, here is the code:

Code:
MSFTime MSF;// = MSFTime();

time_t msfTimeSync();
byte prevStatus = 255;



void setup()                    // run once, when the sketch starts
{
  Serial.begin(9600);

  LedSign::Init(GRAYSCALE);
 
  MSF.init( 255 ); // LED pin for status
   
  setSyncProvider(msfTimeSync);  // tell the Time library what to ask for a new time value

}

time_t msfTimeSync() // called periodically by Time library to syncronise itself
{
   return MSF.getTime();
}


void drawLine( int offset, int val, int range )
{
 
  int total = 9;

  val = val%range;
  int at = ( val * total ) / range; 
 

  for( int i =0; i < at-1; i ++ )
    LedSign::Set(i,offset, 1);
   
  LedSign::Set(at-1, offset, 3);
 
}



int offset = 13;

void loop()                     // run over and over again
{
  LedSign::Clear();
 
  //drawLine( 0, 7, 8);
 
  char buff[20];
  now(); // make sure Time has attempted to sync

  byte currStatus = MSF.getStatus();
 
  #define MESSAGE_LEN 20

  char test[MESSAGE_LEN];
 
  int chars =0;
 
  if( timeStatus() == timeNotSet )
  {
   

     if( ! (currStatus & MSF_STATUS_CARRIER))
       chars = sprintf( test, "NO CARRIER   ");
     else if( (currStatus & MSF_STATUS_WAITING))
     {
       drawLine( 8, MSF.getProgess(), 60 );

       chars = sprintf( test, "WAITING   ");
     }
     else if( (currStatus & MSF_STATUS_READING))
     {
       drawLine( 8, MSF.getProgess(), 60 );

       chars = sprintf( test, "READING   ");
     }
     else
       chars = sprintf( test, "CONFUSED   "); // should never happen
  }
  else
  {
    int mins = MSF.getFixAge()/60000L;
    if( mins < 0 )
      mins = 0;
     
    drawLine( 8, mins, 14 ); // fix age, one LED per min
   chars = sprintf( test, "%02d:%02d:%02d   %02d:%02d:%04d   ", hour(), minute(), second(), day(), month(), year() );
  }


  int8_t x, x2;

  x = offset;
 

  for(int i=0;i<chars;i++)
  {
    x2=Font::Draw(test[i],x,0,3);
    x+=x2;
    if (x>=13) break;
  } 
 
  if( x >= 13 )
    offset --; // there was more stuff to draw off the right, keep scrolling
  else
    offset = 13; // set the scroll back to draw at the right of the screen
   
  delay(80);
   

}
« Last Edit: July 26, 2012, 01:11:48 pm by picmetoo » Logged

Copenhagen, Denmark
Offline Offline
Edison Member
*
Karma: 32
Posts: 1204
Have you testrun your INO file today?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You MUST enclose your code in the code tags (use the "#" icon when entering the code). For example: I see a smiley with sunglasses suddenly in the code instead of a digit and closing bracket. I can guess this is a 8. Also some subscript brackets get "swallowed". Note you can edit the post you have submitted.The above was edited, so now legible.

You're also missing the "#include" of the libraries you are using.
« Last Edit: July 26, 2012, 02:00:19 pm by Msquare » Logged

Austin, TX
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6137
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You defined test to be 20 characters long.  Sprintf() puts a null character at the end, which takes up a character.  Test needs to be bigger.

I'm not sure I understand what you are doing with the variable "chars".  sprintf returns the number of characters written.  "chars" isn't an int, it is an array of characters, why?
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks James C4S,
I Increased it to 30 characters and it works fine.
Logged

Pages: [1]   Go Up
Jump to: