#Arduino Timezone Library v1.0
https://github.com/JChristensen/Timezone
ReadMe file
Jack Christensen Mar 2012
![CC BY-SA](http://mirrors.creativecommons.org/presskit/buttons/80x15/png/by-sa.png)
##Introduction
The **Timezone** library is designed to work in conjunction with the [Arduino Time library](http://www.arduino.cc/playground/Code/Time). The Time library must be installed and referenced in your sketch with `#include <Time.h>`. This documentation assumes some familiarity with the Time library.
The primary aim of the **Timezone** library is to convert Universal Coordinated Time (UTC) to the correct local time, whether it is daylight saving time (a.k.a. summer time) or standard time. The time source could be a GPS receiver, an NTP server, or a Real-Time Clock (RTC) set to UTC. But whether a hardware RTC or other time source is even present is immaterial; although the Time library can function as a software RTC without additional hardware, its accuracy is dependent on the accuracy of the microcontroller's system clock.
The **Timezone** library implements two objects to facilitate time zone conversions:
- A **TimeChangeRule** object describes when local time changes to daylight (summer) time, or to standard time, for a particular locale.
- A **Timezone** object uses **TimeChangeRule**s to perform conversions and related functions. It can also write its **TimeChangeRule**s to EEPROM, or read them from EEPROM. Multiple time zones can be represented by defining multiple **Timezone** objects.
##Installation
To use the **Timezone** library:
- Go to https://github.com/JChristensen/Timezone and click the **Download ZIP** button to download the repository as a ZIP file to a convenient location on your PC.
- Uncompress the downloaded file. This will result in a folder containing all the files for the library, that has a name that includes the branch name, for example **Timezone-master**.
- Rename the folder to just **Timezone**.
- Copy the renamed folder to the Arduino sketchbook\libraries folder.
##Examples
The following example sketches are included with the **Timezone** library:
- **Clock:** A simple self-adjusting clock for a single time zone. **TimeChangeRule**s may be optionally read from EEPROM.
- **HardwareRTC:** A self-adjusting clock for one time zone using an external real-time clock, either a DS1307 or DS3231 (e.g. Chronodot) which is set to UTC.
- **WorldClock:** A self-adjusting clock for multiple time zones.
- **WriteRules:** A sketch to write **TimeChangeRule**s to EEPROM.
##Coding TimeChangeRules
Normally these will be coded in pairs for a given time zone: One rule to describe when daylight (summer) time starts, and one to describe when standard time starts.
As an example, here in the Eastern US time zone, Eastern Daylight Time (EDT) starts on the 2nd Sunday in March at 02:00 local time. Eastern Standard Time (EST) starts on the 1st Sunday in November at 02:00 local time.
Define a **TimeChangeRule** as follows:
`TimeChangeRule myRule = {abbrev, week, dow, month, hour, offset};`
Where:
**abbrev** is a character string abbreviation for the time zone; it must be no longer than five characters.
**week** is the week of the month that the rule starts.
**dow** is the day of the week that the rule starts.
**hour** is the hour in local time that the rule starts (0-23).
**offset** is the UTC offset _in minutes_ for the time zone being defined.
For convenience, the following symbolic names can be used:
**week:** First, Second, Third, Fourth, Last
**dow:** Sun, Mon, Tue, Wed, Thu, Fri, Sat
**month:** Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec
For the Eastern US time zone, the **TimeChangeRule**s could be defined as follows:
```c++
TimeChangeRule usEDT = {"EDT", Second, Sun, Mar, 2, -240}; //UTC - 4 hours
TimeChangeRule usEST = {"EST", First, Sun, Nov, 2, -300}; //UTC - 5 hours
```
For a time zone that does not change to daylight/summer time, pass the same rule twice to the constructor, for example:
`Timezone usAZ(usMST, usMST);`
##Coding Timezone objects
There are two ways to define **Timezone** objects.
By first defining **TimeChangeRule**s (as above) and giving the daylight time rule and the standard time rule (assuming usEDT and usEST defined as above):
`Timezone usEastern(usEDT, usEST);`
By reading rules previously stored in EEPROM. This reads both the daylight and standard time rules previously stored at EEPROM address 100:
`Timezone usPacific(100);`
Note that **TimeChangeRule**s require 12 bytes of storage each, so the pair of rules associated with a Timezone object requires 24 bytes total. This could possibly change in future versions of the library. The size of a **TimeChangeRule** can be checked with `sizeof(usEDT)`.
##Timezone library methods
Note that the `time_t` data type is defined by the Arduino Time library <Time.h>. See the [Time library documentation](http://www.arduino.cc/playground/Code/Time) for additional details.
###time_t toLocal(time_t utc);
#####Description
Converts the given UTC time to local time, standard or daylight as appropriate.
#####Syntax
`myTZ.toLocal(utc);`
#####Parameters
***utc:*** Universal Coordinated Time *(time_t)*
#####Returns
Local time *(time_t)*
#####Example
```c++
time_t eastern, utc;
TimeChangeRule usEDT = {"EDT", Second, Sun, Mar, 2, -240}; //UTC - 4 hours
TimeChangeRule usEST = {"EST", First, Sun, Nov, 2, -300}; //UTC - 5 hours
Timezone usEastern(usEDT, usEST);
utc = now(); //current time from the Time Library
eastern = usEastern.toLocal(utc);
```
###time_t toLocal(time_t utc, TimeChangeRule **tcr);
#####Description
As above, converts the given UTC time to local time, and also returns a pointer to the **TimeChangeRule** that was applied to do the conversion. This could then be used, for example, to include the time zone abbreviation as part of a time display. The caller must take care not to alter the pointed **TimeChangeRule**, as this will then result in incorrect conversions.
#####Syntax
`myTZ.toLocal(utc, &tcr);`
#####Parameters
***utc:*** Universal Coordinated Time *(time_t)*
***tcr:*** Address of a pointer to a **TimeChangeRule** _(\*\*TimeChangeRule)_
#####Returns
Local time *(time_t)*
Pointer to **TimeChangeRule** _(\*\*TimeChangeRule)_
#####Example
```c++
time_t eastern, utc;
TimeChangeRule *tcr;
TimeChangeRule usEDT = {"EDT", Second, Sun, Mar, 2, -240}; //UTC - 4 hours
TimeChangeRule usEST = {"EST", First, Sun, Nov, 2, -300}; //UTC - 5 hours
Timezone usEastern(usEDT, usEST);
utc = now(); //current time from the Time Library
eastern = usEastern.toLocal(utc, &tcr);
Serial.print("The time zone is: ");
Serial.println(tcr -> abbrev);
```
###boolean utcIsDST(time_t utc);
###boolean locIsDST(time_t local);
#####Description
These functions determine whether a given UTC time or a given local time is within the daylight saving (summer) time interval, and return true or false accordingly.
#####Syntax
`utcIsDST(utc);`
`locIsDST(local);`
#####Parameters
***utc:*** Universal Coordinated Time *(time_t)*
***local:*** Local Time *(time_t)*
#####Returns
true or false *(boolean)*
#####Example
`if (usEastern.utcIsDST(utc)) { /*do something*/ }`
###void readRules(int address);
###void writeRules(int address);
#####Description
These functions read or write a **Timezone** object's two **TimeChangeRule**s from or to EEPROM.
#####Syntax
`myTZ.readRules(address);`
`myTZ.writeRules(address);`
#####Parameters
***address:*** The beginning EEPROM address to write to or read from *(int)*
#####Returns
None.
#####Example
`usEastern.writeRules(100); //write rules beginning at EEPROM address 100`
###time_t toUTC(time_t local);
#####Description
Converts the given local time to UTC time.
**WARNING:** This function is provided for completeness, but should seldom be needed and should be used sparingly and carefully.
Ambiguous situations occur after the Standard-to-DST and the DST-to-Standard time transitions. Wh
没有合适的资源?快使用搜索试试~ 我知道了~
ESP8266 EasyIoT 库和传感器示例_ C++_代码_相关文件_下载 NRF24L01+ Arduino
共293个文件
h:95个
ino:92个
c:30个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 124 浏览量
2022-07-13
00:55:07
上传
评论
收藏 3.29MB ZIP 举报
温馨提示
NRF24L01+ Arduino 低功耗传感器 nRF24L01 是一款适用于全球 2.4 - 2.5 GHz ISM 频段的单芯片无线电收发器。该收发器由一个完全集成的频率合成器、一个功率放大器、一个晶体振荡器、一个解调器、调制器和增强型 ShockBurst 协议引擎组成。输出功率、频率通道和协议设置可通过 SPI 接口轻松编程。电流消耗非常低,在 -6dBm 的输出功率下仅为 9.0mA,在 RX 模式下为 12.3mA。内置的掉电和待机模式使省电变得容易实现。 最小电源电压 1.9 V 最大输出功率 0 dBm 最大数据速率 2000 kbps TX 模式下的电源电流 @ 0dBm 输出功率 11.3 mA RX 模式下的电源电流 @ 2000 kbps 12.3 mA 温度范围 -40 至 +85 °C 灵敏度@1000 kbps -85 dBm 掉电模式下的电源电流 900 nA 更多详情、使用方法,请下载后阅读README.md文件
资源推荐
资源详情
资源评论
收起资源包目录
ESP8266 EasyIoT 库和传感器示例_ C++_代码_相关文件_下载 NRF24L01+ Arduino
(293个子文件)
tux.c 198KB
Ubuntu.c 45KB
DefaultFonts.c 42KB
SevenSeg_XXXL_Num.c 39KB
tux.c 37KB
biohazard.c 37KB
biohazard.c 37KB
tux.c 37KB
tux.c 37KB
logo.c 34KB
arial_normal.c 16KB
arial_bold.c 16KB
ArialNumFontPlus.c 11KB
ArialNumFontPlus.c 11KB
SevenSegNumFontPlus.c 11KB
icon2.c 9KB
icon1.c 9KB
icon.c 9KB
info.c 9KB
icon2.c 9KB
icon2.c 9KB
icon1.c 9KB
tux.c 9KB
icon1.c 9KB
icon.c 9KB
icon.c 9KB
info.c 9KB
info.c 9KB
tux.c 9KB
tux.c 9KB
RF24.cpp 37KB
LowPower.cpp 27KB
UTFT.cpp 26KB
MySensor.cpp 17KB
Esp8266EasyIoT.cpp 17KB
DS1302RTC.cpp 11KB
MyMQTT.cpp 11KB
SFE_BMP180.cpp 10KB
Timezone.cpp 9KB
MyGateway.cpp 7KB
HTU21D.cpp 7KB
MsTimer2.cpp 6KB
UTouch.cpp 6KB
DHT.cpp 5KB
MyMessage.cpp 4KB
Irrigation.cpp 4KB
Esp8266EasyIoTMsg.cpp 3KB
ImageConverter565.exe 208KB
ImgConv.exe 25KB
.gitattributes 483B
.gitignore 606B
RF24.h 41KB
PinChangeInt.h 20KB
MySensor.h 10KB
UTFT.h 9KB
MyMessage.h 7KB
Esp8266EasyIoTMsg.h 6KB
HW_SAM3X8E.h 6KB
HW_ATmega32U4.h 5KB
HW_MX20DX256.h 5KB
HW_ATmega1280.h 5KB
SFE_BMP180.h 4KB
RF24_config.h 4KB
HW_ATmega1284P.h 4KB
DS1302RTC.h 4KB
Esp8266EasyIoT.h 4KB
HW_PIC32MX795F512L.h 4KB
initlcd.h 4KB
HW_PIC32MX320F128H.h 4KB
HW_PIC32MX340F512H.h 4KB
nRF24L01.h 3KB
initlcd.h 3KB
HW_ATmega328P.h 3KB
initlcd.h 3KB
initlcd.h 3KB
initlcd.h 3KB
MyMQTT.h 3KB
initlcd.h 3KB
initlcd.h 3KB
Timezone.h 3KB
initlcd.h 3KB
MyGateway.h 3KB
initlcd.h 2KB
initlcd.h 2KB
DHT.h 2KB
memorysaver.h 2KB
initlcd.h 2KB
UTouch.h 2KB
initlcd.h 2KB
initlcd.h 2KB
Irrigation.h 2KB
LowPower.h 2KB
initlcd.h 2KB
initlcd.h 2KB
initlcd.h 2KB
initlcd.h 2KB
initlcd.h 2KB
initlcd.h 2KB
initlcd.h 1KB
initlcd.h 1KB
共 293 条
- 1
- 2
- 3
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9156
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功