查看“Microduino ENC Network (7)”的源代码
←
Microduino ENC Network (7)
跳转至:
导航
、
搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
{{Language | Microduino ENC网络(七)}} {| style="width: 800px;" |- | ==Objective== This tutorial will show you how to control a LED from a web page. ==Equipment== *'''[[Microduino-Core]]''' *'''[[Microduino-FT232R]]''' *'''[[Microduino-ENC28J60]]''' *'''[[Microduino-RJ45]]''' *Other equipment **USB cable ==A bit of HTML== First, you need to write an HTML page that will be the web interface Arduino sends to your web browser: [[File:htmlcode.jpg|600px|center|thumb]] This web page is very simple: a label about LED’s actual status and a button to change it. Looking at page’s HTML source, you can identify the variable elements; i.e. the elements that change according to the LED’s status: From the source, you can also understand what’s going to happen when the user clicks the button: his browser will ask to Arduino a web page named: /?status=ON, if the LED has to be turned on /?status=OFF, if the LED has to be turned off The use of ?name=value to send data to a web server reflects the standard syntax of HTML forms using the GET method. ==Schematic== *Microduino-ENC28J60 *Microduino-RJ45 *Microduino-Core *Microduino-FT232R Stack all modules and then connect the ethernet cable, as follows: [[File:MicroduinoENCLED.jpg|600px|center|thumb]] ==Program== Refer to ENCnetworkseven ==Debug== Step 1:Download the EtherCard library and copy to your libraries fold of IDE, then restart IDE. https://github.com/jcw/ethercard Step 2:Explain the program: //Two static strings (ON, OFF) and two variables are defined: the variables will be used in HTML page creation, associating to them one of the two static strings. char* on = "ON"; char* off = "OFF"; char* statusLabel; char* buttonLabel; //In the setup(), in addition to EtherCard library setup, LED’s initial status (off) is configured. pinMode(ledPin, OUTPUT); digitalWrite(ledPin, LOW); ledStatus = false; //In the main loop(), our sketch parse browser’s request (saved in Ethernet::buffer buffer starting from pos position) looking for status ON/OFF commands. if(strstr((char *)Ethernet::buffer + pos, "GET /?status=ON") != 0) { Serial.println("Received ON command"); ledStatus = true; } if(strstr((char *)Ethernet::buffer + pos, "GET /?status=OFF") != 0) { Serial.println("Received OFF command"); ledStatus = false; } //The status of ledPin (Arduino’s PIN the LED is connected to) is updated and the two string variables are associated to the correct labels: if(ledStatus) { digitalWrite(ledPin, HIGH); statusLabel = on; buttonLabel = off; } else { digitalWrite(ledPin, LOW); statusLabel = off; buttonLabel = on; } Step 3: Connect the bulb, as follws: [[File:connectLED.jpg|600px|center|thumb]] Step 4:Copile the code and download it. Step 5:Use the browser to access the Microduino's IP, then click ON/OFF, observe the bulb's state. ==Result== Access Microduino's IP, you will see following picture: [[File:LEDWebPage.jpg|600px|center|thumb]] Then you can use the browser to control the bulb. ==Video== http://v.youku.com/v_show/id_XNzAzMzM0NzUy.html |}
该页面使用的模板:
模板:Language
(
查看源代码
)
模板:Nmbox
(
查看源代码
)
返回至
Microduino ENC Network (7)
。
导航菜单
个人工具
创建账户
登录
名字空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
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
帮助
常见问题
帮助
工具
链入页面
相关更改
特殊页面
页面信息