Storing time in a char array for oled display

Hi,

I'm using a SSD1306 128x64 OLED with the U8G library. I'm building a small clock with it and starting off by just having it count up seconds. Right now, I have it displaying a number in the middle, waiting one second, and then increasing the number by one to display again. Once the counter reaches 60, it starts over again. I need to store the number in a char array or string so that the code can read the height and width of the text in order to center it.

It won't let me store the variable in it and I don't know what else to use.

#include "U8glib.h" //includes the u8g library for OLED screens

U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE); //setup u8g object

int seconds = 0;

char timearray[] = seconds; //store elapsed seconds in a char array

void setup()
{

}


void loop()
{
  u8g.firstPage(); //initialize picture loop
  do
  {
    drawTime(); //graphic command to display time
  }
  while(u8g.nextPage());
}


void drawTime() //drawTime function used in the loop
{
  u8g.setFont(u8g_font_fur17); //set the font
  int textHeight = u8g.getFontAscent(); //get the height of the font
  
  int linex = (u8g.getWidth() - u8g.getStrWidth(timearray))/2; //find the starting point for the word
  int liney = ((64 - textHeight)/2) + textHeight; //set the text in the middle. This takes the screen height - text height in half, then adds the text height since it uses the bottom right corner 
  u8g.drawStr(linex,liney,timearray); //print seconds
  delay(1000);
  seconds = seconds + 1; //add 1 second on
  if(seconds == 60) //if 60 seconds has elapsed then...
  {
    seconds = 0; //reset the seconds counter
  }
  
}

Also, I don't know if this will refresh the screen or not and even display the numbers properly every second. Any advice?

I need to store the number in a char array

The one called timearray?

You've only provided one initializer (incorrectly), so you get a one element array. You can't store much in a one element array.

   // global
   char timeArray[10];

   // in the drawTime function 
   itoa(seconds, timeArray, 10);

I'm not familiar with ITOA. From what I've read, it converts the int seconds into a string to store in my array. Then, can I just use the array like normal in the drawTime function?

PaulS:
The one called timearray?

You've only provided one initializer (incorrectly), so you get a one element array. You can't store much in a one element array.

   // global

char timeArray[10];

// in the drawTime function
  itoa(seconds, timeArray, 10);

Ok, so I added this to my code. Ta-da, it counts up now. Except it counts in 10s and doesn't update quite right. The characters are all shifted, almost broken halfway down the middle horizontally. It also doesn't count at an even rate. I had to move the delay to the loop, if that helps.

void loop()
{
  u8g.firstPage(); //initialize picture loop
  do
  {
    drawTime(); //graphic command to display time
  }
  while(u8g.nextPage());
  delay(1000);
}

post full code (or build a small code demonstrating your pb if the rest of your code is irrelevant)