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.
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.
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);
}
~~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.
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?