Use the in built C time.h library to power a clock and output on dispBoB

Dependencies:   dispBoB mbed PCA9635

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers simpleClock.cpp Source File

simpleClock.cpp

00001 #include "mbed.h"
00002 #include "dispBoB.h"
00003 
00004 dispBoB db(p28, p27, p26);              //instantiate dispBoB object
00005 
00006 int main() {
00007     db.init();
00008     set_time(1309776930);               //set UNIX timestamp -  it's Mon, 04 Jul 2011 10:55:30 GMT where I am
00009     
00010     while(1){                           //loop forever
00011         time_t rawtime = time(NULL);    //update to instantaneous time
00012         
00013         char buffer[32];                //create a local char array object called buffer
00014         strftime(buffer, 32, "%H.%M.%S\n", localtime(&rawtime)); //store string formatted time
00015         
00016         db.locate(0);                   //position cursor to initial position on screen
00017         db.printf("%s", buffer);        //print buffer to dispBoB
00018     }
00019 }