我用的是2560和W5100 Test
#include<SPI.h>
#include<Ethernet.h>
byte mac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};
byte ip[]={192,168,0,15};
byte gateway[]={192,168,0,1};
byte subnet[]={255,255,255,0};
EthernetServer server(80);
void setup()
{
Serial.begin(9600);
SPI.begin()
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
pinMode(3,OUTPUT);
digitalWrite(3,HIGH);
Ethernet.begin(mac,ip,gateway,subnet);
server.begin();
}
void loop()
{
EthernetClient client=server.available();
if(clinet)
{
boolean currentLineIsBlank=true;
while(client.connected())
{
if(client.connected())
{
char c=client.read();
if(c=='\n' &¤tLineIsBlank)
{
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.print("horizontal:");
client.print(analogRead(1));
client.println("<br/>");
client.print("vertical");
client.print(analogRead(0));
break;
}
if(c=='\n')
{
currentLinIsBlank=true;
}
else if(c!='\r')
{
currentLinIsBlank=false;
}
}
}
delay(1);
client.stop();
}
}
|