Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
my_xihale
Time
提交
4a93ec6b
T
Time
项目概览
my_xihale
/
Time
与 Fork 源项目一致
从无法访问的项目Fork
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Time
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
4a93ec6b
编写于
1月 01, 2021
作者:
my_xihale
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
删除 TimeSerial.ino
上级
410aee4f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
0 addition
and
81 deletion
+0
-81
examples/TimeSerial/TimeSerial.ino
examples/TimeSerial/TimeSerial.ino
+0
-81
未找到文件。
examples/TimeSerial/TimeSerial.ino
已删除
100644 → 0
浏览文件 @
410aee4f
/*
* TimeSerial.pde
* example code illustrating Time library set through serial port messages.
*
* Messages consist of the letter T followed by ten digit time (as seconds since Jan 1 1970)
* you can send the text on the next line using Serial Monitor to set the clock to noon Jan 1 2013
T1357041600
*
* A Processing example sketch to automatically send the messages is included in the download
* On Linux, you can use "date +T%s\n > /dev/ttyACM0" (UTC time zone)
*/
#include <TimeLib.h>
#define TIME_HEADER "T" // Header tag for serial time sync message
#define TIME_REQUEST 7 // ASCII bell character requests a time sync message
void
setup
()
{
Serial
.
begin
(
9600
);
while
(
!
Serial
)
;
// Needed for Leonardo only
pinMode
(
13
,
OUTPUT
);
setSyncProvider
(
requestSync
);
//set function to call when sync required
Serial
.
println
(
"Waiting for sync message"
);
}
void
loop
(){
if
(
Serial
.
available
())
{
processSyncMessage
();
}
if
(
timeStatus
()
!=
timeNotSet
)
{
digitalClockDisplay
();
}
if
(
timeStatus
()
==
timeSet
)
{
digitalWrite
(
13
,
HIGH
);
// LED on if synced
}
else
{
digitalWrite
(
13
,
LOW
);
// LED off if needs refresh
}
delay
(
1000
);
}
void
digitalClockDisplay
(){
// digital clock display of the time
Serial
.
print
(
hour
());
printDigits
(
minute
());
printDigits
(
second
());
Serial
.
print
(
" "
);
Serial
.
print
(
day
());
Serial
.
print
(
" "
);
Serial
.
print
(
month
());
Serial
.
print
(
" "
);
Serial
.
print
(
year
());
Serial
.
println
();
}
void
printDigits
(
int
digits
){
// utility function for digital clock display: prints preceding colon and leading 0
Serial
.
print
(
":"
);
if
(
digits
<
10
)
Serial
.
print
(
'0'
);
Serial
.
print
(
digits
);
}
void
processSyncMessage
()
{
unsigned
long
pctime
;
const
unsigned
long
DEFAULT_TIME
=
1357041600
;
// Jan 1 2013
if
(
Serial
.
find
(
TIME_HEADER
))
{
pctime
=
Serial
.
parseInt
();
if
(
pctime
>=
DEFAULT_TIME
)
{
// check the integer is a valid time (greater than Jan 1 2013)
setTime
(
pctime
);
// Sync Arduino clock to the time received on the serial port
}
}
}
time_t
requestSync
()
{
Serial
.
write
(
TIME_REQUEST
);
return
0
;
// the time will be sent later in response to serial mesg
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录