A simple serial test program for the ISL1208 library.

Dependencies:   ISL1208 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "ISL1208.h"
00003 
00004 ISL1208 rtc(p28, p27);
00005 
00006 int main()
00007 {
00008     //Try to open the ISL1208
00009     if (rtc.open()) {
00010         printf("Device detected!\n");
00011 
00012         //Configure the oscillator for a 32.768kHz crystal
00013         rtc.oscillatorMode(ISL1208::OSCILLATOR_CRYSTAL);
00014 
00015         //Check if we need to reset the time
00016         if (rtc.powerFailed()) {
00017             //The time has been lost due to a power complete power failure
00018             printf("Device has lost power! Resetting time...\n");
00019 
00020             //Set RTC time to Wed, 28 Oct 2009 11:35:37
00021             rtc.time(1256729737);
00022         }
00023 
00024         while(1) {
00025             //Get the current time
00026             time_t seconds = rtc.time();
00027 
00028             //Print the time in various formats
00029             printf("\nTime as seconds since January 1, 1970 = %d\n", seconds);
00030             printf("Time as a basic string = %s", ctime(&seconds));
00031             char buffer[32];
00032             strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds));
00033             printf("Time as a custom formatted string = %s", buffer);
00034 
00035             //Delay for 1.0 seconds
00036             wait(1.0);
00037         }
00038     } else {
00039         error("Device not detected!\n");
00040     }
00041 }