查看“To Obtain Network Time”的源代码
←
To Obtain Network Time
跳转至:
导航
、
搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
{| style="width: 800px;" |- | ==Objective== The course will teach you how to use Processing to display the network time acquired by Microduino. ==Equipment== *'''[[Microduino-Core]]''' *'''[[Microduino-FT232R]]''' *'''[[Microduino-ENC28J60]]''' *'''[[Microduino-RJ45]]''' *Other Hardware Equipment **A USB cable ==Schematic== Just stack the four Microduino modules mentioned above. ==Program== https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_Processing/MicroduinnoNetTime https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_Processing/ProcessingNetTime ==Debugging== Step 1:Build the hardware environment according to the schematic, as follows: [[File:MicroduinoENCShow.jpg|600px|center|thumb]] The hardware buildup can refer to: http://www.microduino.cc/wiki/index.php?title=Microduino_ENC%E7%BD%91%E7%BB%9C%EF%BC%88%E5%8D%81%E4%BA%8C%EF%BC%89%E2%80%94%E2%80%94%E2%80%94%E2%80%94%E7%94%A8NTP%E8%8E%B7%E5%8F%96Internet%E6%97%B6%E9%97%B4/zh Step 2:Here is the code needed: The code of the two ends(Processing and Microduino) Microduino: There are many time servers on the internet such as the time server offered by American’s NIST(National Institute of Standards and Technology) and the time server provided by Italy’s INRiM(Istituto Nazionale di Ricerca Metereologica): static byte ntpServer[] = {193,204,114,232}; There are two methods for NTP request: *ntpRequest(ntpServer, srcPort),sending a request to the fixed server; *ntpProcessAnswer(&timeStamp, srcPort), extracting time stamp(Only the first 32 bits) and acquiring response. The srcPort parameter is used to find a data packets containing NTP server response among many receiving packets of the ENC28J60 module. You can choose the value according to individual needs, but the parameters in the ntpRequest and ntpProcessAnswer methods should remain the same. After acquiring the value of the time stamp, you have to convert it into data-time format. As follows: *Calculate the corresponding number of years of the time stamp; *Calculate how many months left in the rest of the time; *Work out date, hour and minute with the same way; *The last remaining is the number of seconds. Mistakes easily to be made: Leap Year probably: If it is Leap Year, 365*86500 seconds must be replaced by 366*86500 seconds. Here is the way to judge whether it is Leap Year: boolean isLeapYear(unsigned int year) { return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); } Since the number of days in each month changes, you should put these values in an array. Here is the format: static int days_in_month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; If it is Leap Year, there are 29 days in February: if(isLeapYear(year) && month == 1) seconds = SECONDS_IN_DAY * 29; The time stamp refers to GMT(Greenwich Mean Time). If you live in a different time zone, you must correct the value: #define TIME_ZONE +1 [...] printDate(timeStamp + 3600 * TIME_ZONE); Processing: //Acquire the data of the first serial port and define it. Or cache it if there is a new line println(Serial.list()); // is always my Arduino, so I open Serial.list()[0]. // Open whatever port is the one you're using. myPort = new Serial(this, Serial.list()[0], 9600); myPort.bufferUntil('\n'); // Trigger a SerialEvent on new line //Read the serial data, intercept the time information and display it //read port data String val = myPort.readStringUntil('\n'); if (val != null) { val = trim(val); println(val); if (val.startsWith("time:")) { //if some exception happend, initial time is 0 colock try { timeShow=val.substring(5,13); } catch (NumberFormatException e) { println("error:"+val); } //Display Text text ( timeShow, 90, 120); } } Step 3:Download the code and get it compiled successfully. Step 4:See what happens in Processing. ==Result== There will appear network time on the screen [[File:processingNetTimeResult.jpg|600px|center|thumb]] ==Video== |}
返回至
To Obtain Network Time
。
导航菜单
个人工具
创建账户
登录
名字空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
Welcome
首页
创客大赛
大赛详情
3D打印
安装月球车
图形化编程
操控月球车
升级月球车
编程工具下载
软件下载
Arduino
Processing
Mixly
Scratch
模块套件
Microduino 102
mCookie 102
mCookie 202
mCookie 302
IBC
其他
应用套件
四轴飞行器
平衡车
小车CUBE
音乐播放器
刷卡音乐播放器
wifi气象站
彩虹音乐触摸灯
分贝检测仪
迎门汇报
LED点阵时钟
LED点阵屏幕
硬件
mCookie
Sensor
Microduino
MicroWrt
MicroNux
MicroRobot-Core
MicroRobot-CoreESP
ideaBoard
ideaBox
MicroMV
MicroAI
帮助
常见问题
帮助
工具
链入页面
相关更改
特殊页面
页面信息