Overview
In the previous post, I showed about a basic usage of SH1106 OLED GLCD. With the Arduino millis() function, we can use it to display the power up time. This function counts the Arduino start up time. It return the time in milli seconds. I can count up to 50 days before it overflows and return back to zero.
A sample Program |
The graphical LCD has an advantage of scalable fonts and graphic. So we can use any preferred font type and size.
In this example, I use this timing function to display the powered up time in HH:MM:SS, with the days counts since started up.
With u8glib library, we can select any font with its size to fit the display.
Schematic |
Arduino Code
#include "U8glib.h"
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE);
unsigned long myMilli=0;
unsigned int secs,mins,hours,days;
void displayText1(void){
u8g.setFont(u8g_font_timB10);
u8g.setPrintPos(0,10);
u8g.print("Powered Up Times:");
u8g.setFont(u8g_font_courB18);
u8g.setPrintPos(20,35);
u8g.print(String(hours%60)+":"+String(mins%60)+":"+String(secs%60));
u8g.setFont(u8g_font_timB10);
u8g.setPrintPos(0,55);
u8g.print("Days:");
u8g.setFont(u8g_font_courB18);
u8g.setPrintPos(50,60);
u8g.print(String(days));
}
void graphicTask(void){
u8g.firstPage();
do{
displayText1();
}while(u8g.nextPage());
}
void setup(void) {
}
void loop(void) {
myMilli=millis();
secs=myMilli/1000;
mins=secs/60;
hours=mins/60;
days=hours/24;
graphicTask();
}
Click here to download Arduino sketch.
No comments:
Post a Comment