mbed
Dependents: DHTSensor_Test K64F_eCompass_OneNET_JW
rtc_time.h@0:2cc6bb4d7fea, 2015-02-25 (annotated)
- Committer:
- mbotkinl
- Date:
- Wed Feb 25 20:22:22 2015 +0000
- Revision:
- 0:2cc6bb4d7fea
Working code to read Temperature and Humidity readings
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbotkinl | 0:2cc6bb4d7fea | 1 | /* mbed Microcontroller Library |
mbotkinl | 0:2cc6bb4d7fea | 2 | * Copyright (c) 2006-2013 ARM Limited |
mbotkinl | 0:2cc6bb4d7fea | 3 | * |
mbotkinl | 0:2cc6bb4d7fea | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
mbotkinl | 0:2cc6bb4d7fea | 5 | * you may not use this file except in compliance with the License. |
mbotkinl | 0:2cc6bb4d7fea | 6 | * You may obtain a copy of the License at |
mbotkinl | 0:2cc6bb4d7fea | 7 | * |
mbotkinl | 0:2cc6bb4d7fea | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbotkinl | 0:2cc6bb4d7fea | 9 | * |
mbotkinl | 0:2cc6bb4d7fea | 10 | * Unless required by applicable law or agreed to in writing, software |
mbotkinl | 0:2cc6bb4d7fea | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
mbotkinl | 0:2cc6bb4d7fea | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbotkinl | 0:2cc6bb4d7fea | 13 | * See the License for the specific language governing permissions and |
mbotkinl | 0:2cc6bb4d7fea | 14 | * limitations under the License. |
mbotkinl | 0:2cc6bb4d7fea | 15 | */ |
mbotkinl | 0:2cc6bb4d7fea | 16 | |
mbotkinl | 0:2cc6bb4d7fea | 17 | #include <time.h> |
mbotkinl | 0:2cc6bb4d7fea | 18 | |
mbotkinl | 0:2cc6bb4d7fea | 19 | #ifdef __cplusplus |
mbotkinl | 0:2cc6bb4d7fea | 20 | extern "C" { |
mbotkinl | 0:2cc6bb4d7fea | 21 | #endif |
mbotkinl | 0:2cc6bb4d7fea | 22 | |
mbotkinl | 0:2cc6bb4d7fea | 23 | /** Implementation of the C time.h functions |
mbotkinl | 0:2cc6bb4d7fea | 24 | * |
mbotkinl | 0:2cc6bb4d7fea | 25 | * Provides mechanisms to set and read the current time, based |
mbotkinl | 0:2cc6bb4d7fea | 26 | * on the microcontroller Real-Time Clock (RTC), plus some |
mbotkinl | 0:2cc6bb4d7fea | 27 | * standard C manipulation and formating functions. |
mbotkinl | 0:2cc6bb4d7fea | 28 | * |
mbotkinl | 0:2cc6bb4d7fea | 29 | * Example: |
mbotkinl | 0:2cc6bb4d7fea | 30 | * @code |
mbotkinl | 0:2cc6bb4d7fea | 31 | * #include "mbed.h" |
mbotkinl | 0:2cc6bb4d7fea | 32 | * |
mbotkinl | 0:2cc6bb4d7fea | 33 | * int main() { |
mbotkinl | 0:2cc6bb4d7fea | 34 | * set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37 |
mbotkinl | 0:2cc6bb4d7fea | 35 | * |
mbotkinl | 0:2cc6bb4d7fea | 36 | * while(1) { |
mbotkinl | 0:2cc6bb4d7fea | 37 | * time_t seconds = time(NULL); |
mbotkinl | 0:2cc6bb4d7fea | 38 | * |
mbotkinl | 0:2cc6bb4d7fea | 39 | * printf("Time as seconds since January 1, 1970 = %d\n", seconds); |
mbotkinl | 0:2cc6bb4d7fea | 40 | * |
mbotkinl | 0:2cc6bb4d7fea | 41 | * printf("Time as a basic string = %s", ctime(&seconds)); |
mbotkinl | 0:2cc6bb4d7fea | 42 | * |
mbotkinl | 0:2cc6bb4d7fea | 43 | * char buffer[32]; |
mbotkinl | 0:2cc6bb4d7fea | 44 | * strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds)); |
mbotkinl | 0:2cc6bb4d7fea | 45 | * printf("Time as a custom formatted string = %s", buffer); |
mbotkinl | 0:2cc6bb4d7fea | 46 | * |
mbotkinl | 0:2cc6bb4d7fea | 47 | * wait(1); |
mbotkinl | 0:2cc6bb4d7fea | 48 | * } |
mbotkinl | 0:2cc6bb4d7fea | 49 | * } |
mbotkinl | 0:2cc6bb4d7fea | 50 | * @endcode |
mbotkinl | 0:2cc6bb4d7fea | 51 | */ |
mbotkinl | 0:2cc6bb4d7fea | 52 | |
mbotkinl | 0:2cc6bb4d7fea | 53 | /** Set the current time |
mbotkinl | 0:2cc6bb4d7fea | 54 | * |
mbotkinl | 0:2cc6bb4d7fea | 55 | * Initialises and sets the time of the microcontroller Real-Time Clock (RTC) |
mbotkinl | 0:2cc6bb4d7fea | 56 | * to the time represented by the number of seconds since January 1, 1970 |
mbotkinl | 0:2cc6bb4d7fea | 57 | * (the UNIX timestamp). |
mbotkinl | 0:2cc6bb4d7fea | 58 | * |
mbotkinl | 0:2cc6bb4d7fea | 59 | * @param t Number of seconds since January 1, 1970 (the UNIX timestamp) |
mbotkinl | 0:2cc6bb4d7fea | 60 | * |
mbotkinl | 0:2cc6bb4d7fea | 61 | * Example: |
mbotkinl | 0:2cc6bb4d7fea | 62 | * @code |
mbotkinl | 0:2cc6bb4d7fea | 63 | * #include "mbed.h" |
mbotkinl | 0:2cc6bb4d7fea | 64 | * |
mbotkinl | 0:2cc6bb4d7fea | 65 | * int main() { |
mbotkinl | 0:2cc6bb4d7fea | 66 | * set_time(1256729737); // Set time to Wed, 28 Oct 2009 11:35:37 |
mbotkinl | 0:2cc6bb4d7fea | 67 | * } |
mbotkinl | 0:2cc6bb4d7fea | 68 | * @endcode |
mbotkinl | 0:2cc6bb4d7fea | 69 | */ |
mbotkinl | 0:2cc6bb4d7fea | 70 | void set_time(time_t t); |
mbotkinl | 0:2cc6bb4d7fea | 71 | |
mbotkinl | 0:2cc6bb4d7fea | 72 | #ifdef __cplusplus |
mbotkinl | 0:2cc6bb4d7fea | 73 | } |
mbotkinl | 0:2cc6bb4d7fea | 74 | #endif |