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?