
A simple serial test program for the ISL1208 library.
main.cpp@0:48943967d624, 2013-09-09 (annotated)
- Committer:
- neilt6
- Date:
- Mon Sep 09 19:34:12 2013 +0000
- Revision:
- 0:48943967d624
- Child:
- 1:e983c454f8be
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
neilt6 | 0:48943967d624 | 1 | #include "mbed.h" |
neilt6 | 0:48943967d624 | 2 | #include "ISL1208.h" |
neilt6 | 0:48943967d624 | 3 | |
neilt6 | 0:48943967d624 | 4 | ISL1208 rtc(p28, p27); |
neilt6 | 0:48943967d624 | 5 | |
neilt6 | 0:48943967d624 | 6 | int main() |
neilt6 | 0:48943967d624 | 7 | { |
neilt6 | 0:48943967d624 | 8 | //Try to open the ISL1208 |
neilt6 | 0:48943967d624 | 9 | if (rtc.open(ISL1208::OSCILLATOR_CRYSTAL)) { |
neilt6 | 0:48943967d624 | 10 | printf("Device detected!\n"); |
neilt6 | 0:48943967d624 | 11 | |
neilt6 | 0:48943967d624 | 12 | //Check if we need to reset the time |
neilt6 | 0:48943967d624 | 13 | if (rtc.powerFailed()) { |
neilt6 | 0:48943967d624 | 14 | //The time has been lost due to a power complete power failure |
neilt6 | 0:48943967d624 | 15 | printf("Device has lost power! Resetting time...\n"); |
neilt6 | 0:48943967d624 | 16 | |
neilt6 | 0:48943967d624 | 17 | //Set RTC time to Wed, 28 Oct 2009 11:35:37 |
neilt6 | 0:48943967d624 | 18 | rtc.time(1256729737); |
neilt6 | 0:48943967d624 | 19 | } |
neilt6 | 0:48943967d624 | 20 | |
neilt6 | 0:48943967d624 | 21 | while(1) { |
neilt6 | 0:48943967d624 | 22 | //Get the current time |
neilt6 | 0:48943967d624 | 23 | time_t seconds = rtc.time(); |
neilt6 | 0:48943967d624 | 24 | |
neilt6 | 0:48943967d624 | 25 | //Print the time in various formats |
neilt6 | 0:48943967d624 | 26 | printf("\nTime as seconds since January 1, 1970 = %d\n", seconds); |
neilt6 | 0:48943967d624 | 27 | printf("Time as a basic string = %s", ctime(&seconds)); |
neilt6 | 0:48943967d624 | 28 | char buffer[32]; |
neilt6 | 0:48943967d624 | 29 | strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds)); |
neilt6 | 0:48943967d624 | 30 | printf("Time as a custom formatted string = %s", buffer); |
neilt6 | 0:48943967d624 | 31 | |
neilt6 | 0:48943967d624 | 32 | //Delay for 1.0 seconds |
neilt6 | 0:48943967d624 | 33 | wait(1.0); |
neilt6 | 0:48943967d624 | 34 | } |
neilt6 | 0:48943967d624 | 35 | } else { |
neilt6 | 0:48943967d624 | 36 | printf("Device not detected!\n"); |
neilt6 | 0:48943967d624 | 37 | } |
neilt6 | 0:48943967d624 | 38 | } |