极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5707|回复: 0

做了个ENC28J60 用网页遥控灯的小东西。代码不知道能不能精简一下。

[复制链接]
发表于 2013-9-28 12:45:45 | 显示全部楼层 |阅读模式
本帖最后由 wwwzjy 于 2013-9-28 12:50 编辑

不知道为啥,网页只能显示到LED16,再多的话网页就打不开了。






  1. #include <EtherCard.h>

  2. #include <RCSwitch.h>

  3. RCSwitch mySwitch = RCSwitch();

  4. static byte mymac[] = {
  5.   0x47,0x96,0x69,0xD2,0x03,0x13};
  6. byte Ethernet::buffer[700];


  7. void setup () {

  8.   Serial.begin(57600);
  9.   Serial.println("WebLeds Demo");


  10.   // Transmitter is connected to Arduino Pin #10  
  11.   mySwitch.enableTransmit(3);

  12.   // Optional set pulse length.
  13.   // mySwitch.setPulseLength(320);

  14.   // Optional set protocol (default is 1, will work for most outlets)
  15.   // mySwitch.setProtocol(2);

  16.   // Optional set number of transmission repetitions.
  17.   // mySwitch.setRepeatTransmit(15);


  18.   if (!ether.begin(sizeof Ethernet::buffer, mymac, 10))
  19.     Serial.println( "Failed to access Ethernet controller");
  20.   else
  21.     Serial.println("Ethernet controller initialized");

  22.   if (!ether.dhcpSetup())
  23.     Serial.println("Failed to get configuration from DHCP");
  24.   else
  25.     Serial.println("DHCP configuration done");

  26.   ether.printIp("IP Address:\t", ether.myip);
  27.   ether.printIp("Netmask:\t", ether.mymask);
  28.   ether.printIp("Gateway:\t", ether.gwip);
  29. }

  30. void loop() {

  31.   word len = ether.packetReceive();
  32.   word pos = ether.packetLoop(len);

  33.   if(pos) {

  34.     if(strstr((char *)Ethernet::buffer + pos, "GET /?LED01") != 0) {
  35.       Serial.print((char *)Ethernet::buffer + pos);
  36.       mySwitch.send(1000, 24);
  37.     }

  38.     if(strstr((char *)Ethernet::buffer + pos, "GET /?LED02") != 0) {
  39.       Serial.print((char *)Ethernet::buffer + pos);
  40.       mySwitch.send(2000, 24);      
  41.     }

  42.     if(strstr((char *)Ethernet::buffer + pos, "GET /?LED03") != 0) {
  43.       Serial.print((char *)Ethernet::buffer + pos);
  44.       mySwitch.send(3000, 24);      
  45.     }

  46.     if(strstr((char *)Ethernet::buffer + pos, "GET /?LED04") != 0) {
  47.       Serial.print((char *)Ethernet::buffer + pos);
  48.       mySwitch.send(4000, 24);      
  49.     }

  50.     if(strstr((char *)Ethernet::buffer + pos, "GET /?LED05") != 0) {
  51.       Serial.print((char *)Ethernet::buffer + pos);
  52.       mySwitch.send(5000, 24);      
  53.     }

  54.     if(strstr((char *)Ethernet::buffer + pos, "GET /?LED06") != 0) {
  55.       Serial.print((char *)Ethernet::buffer + pos);
  56.       mySwitch.send(6000, 24);      
  57.     }

  58.     if(strstr((char *)Ethernet::buffer + pos, "GET /?LED07") != 0) {
  59.       Serial.print((char *)Ethernet::buffer + pos);
  60.       mySwitch.send(7000, 24);      
  61.     }

  62.     if(strstr((char *)Ethernet::buffer + pos, "GET /?LED08") != 0) {
  63.       Serial.print((char *)Ethernet::buffer + pos);
  64.       mySwitch.send(8000, 24);      
  65.     }

  66.     if(strstr((char *)Ethernet::buffer + pos, "GET /?LED09") != 0) {
  67.       Serial.print((char *)Ethernet::buffer + pos);
  68.       mySwitch.send(9000, 24);      
  69.     }

  70.     if(strstr((char *)Ethernet::buffer + pos, "GET /?LED10") != 0) {
  71.       Serial.print((char *)Ethernet::buffer + pos);
  72.       mySwitch.send(10000, 24);      
  73.     }

  74.     if(strstr((char *)Ethernet::buffer + pos, "GET /?LED11") != 0) {
  75.       Serial.print((char *)Ethernet::buffer + pos);
  76.       mySwitch.send(11000, 24);      
  77.     }

  78.     if(strstr((char *)Ethernet::buffer + pos, "GET /?LED12") != 0) {
  79.       Serial.print((char *)Ethernet::buffer + pos);
  80.       mySwitch.send(12000, 24);      
  81.     }

  82.     if(strstr((char *)Ethernet::buffer + pos, "GET /?LED13") != 0) {
  83.       Serial.print((char *)Ethernet::buffer + pos);
  84.       mySwitch.send(13000, 24);      
  85.     }

  86.     if(strstr((char *)Ethernet::buffer + pos, "GET /?LED14") != 0) {
  87.       Serial.print((char *)Ethernet::buffer + pos);
  88.       mySwitch.send(14000, 24);      
  89.     }

  90.     if(strstr((char *)Ethernet::buffer + pos, "GET /?LED15") != 0) {
  91.       Serial.print((char *)Ethernet::buffer + pos);
  92.       mySwitch.send(15000, 24);      
  93.     }

  94.     if(strstr((char *)Ethernet::buffer + pos, "GET /?LED16") != 0) {
  95.       Serial.print((char *)Ethernet::buffer + pos);
  96.       mySwitch.send(16000, 24);      
  97.     }

  98.     if(strstr((char *)Ethernet::buffer + pos, "GET /?LED17") != 0) {
  99.       Serial.print((char *)Ethernet::buffer + pos);
  100.       mySwitch.send(17000, 24);      
  101.     }

  102.     if(strstr((char *)Ethernet::buffer + pos, "GET /?LED18") != 0) {
  103.       Serial.print((char *)Ethernet::buffer + pos);
  104.       mySwitch.send(18000, 24);      
  105.     }

  106.     if(strstr((char *)Ethernet::buffer + pos, "GET /?LED19") != 0) {
  107.       Serial.print((char *)Ethernet::buffer + pos);
  108.       mySwitch.send(19000, 24);      
  109.     }

  110.     if(strstr((char *)Ethernet::buffer + pos, "GET /?LED20") != 0) {
  111.       Serial.print((char *)Ethernet::buffer + pos);
  112.       mySwitch.send(20000, 24);      
  113.     }



  114.     BufferFiller bfill = ether.tcpOffset();
  115.     bfill.emit_p(PSTR("HTTP/1.0 200 OK\r\n"
  116.       "Content-Type: text/html\r\nPragma: no-cache\r\n\r\n"
  117.       "<html><head><title>WebLeds</title></head><body>"
  118.       "Toggle leds: "

  119.       "<br /><a href="/?LED01">LED01</a>"
  120.       "<br /><a href="/?LED02">LED02</a>"
  121.       "<br /><a href="/?LED03">LED03</a>"
  122.       "<br /><a href="/?LED04">LED04</a>"
  123.       "<br /><a href="/?LED05">LED05</a>"
  124.       "<br /><a href="/?LED06">LED06</a>"
  125.       "<br /><a href="/?LED07">LED07</a>"
  126.       "<br /><a href="/?LED08">LED08</a>"
  127.       "<br /><a href="/?LED09">LED09</a>"
  128.       "<br /><a href="/?LED10">LED10</a>"
  129.       "<br /><a href="/?LED11">LED11</a>"
  130.       "<br /><a href="/?LED12">LED12</a>"
  131.       "<br /><a href="/?LED13">LED13</a>"
  132.       "<br /><a href="/?LED14">LED14</a>"
  133.       "<br /><a href="/?LED15">LED15</a>"
  134.       "<br /><a href="/?LED16">LED16</a>"


  135.    
  136.       "</body></html>"));
  137.     ether.httpServerReply(bfill.position());
  138.   }

  139. }
复制代码



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-8 13:36 , Processed in 0.040387 second(s), 17 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表