Saludos
Tome el Sketch de [SOLVED] Arduino with Ethernet Shield: Trying to have button click blink an LED. - #4 by max_saeta - Programming Questions - Arduino Forum
Y lo modifique para que lo pruebes
#include <SPI.h>
#include <Ethernet.h>
int PIN_LED[8]={5, 6, 7, 8, 9 , 11, 12, 13};
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 10,0,0,14 }; // ip in lan (that's what you need to use in your browser. ("192.168.1.178")
byte gateway[] = { 10,0,0,1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(666); //server port
String readString;
boolean red_blink = false;
unsigned long my_time;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
for(int i = 0; i <8; i++){
pinMode(PIN_LED[i],OUTPUT);
digitalWrite(PIN_LED[i],LOW);
}
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
//if HTTP request has ended
if (c == '\n') {
Serial.println(readString); //print to serial monitor for debuging
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println();
client.println("<HTML>");
client.println("<HEAD>");
client.println("<meta name='apple-mobile-web-app-capable' content='yes' />");
client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");
client.println("<link rel='stylesheet' type='text/css' href='http://randomnerdtutorials.com/ethernetcss.css' />");
client.println("<TITLE>Beyerlin Home Automation System</TITLE>");
client.println("</HEAD>");
client.println("<BODY>");
client.print("<body style=background:gray>");
client.println("<H1>Beyerlin Home Automation Service</H1>");
client.println("<hr />");
client.println("
");
client.println("<H2>User Interface Control Panel</H2>");
client.println("
");
client.println("<a href=\"/?button1on\"\"> LED 1 ON</a>");
client.println("<a href=\"/?button1off\"\"> LED 1 OFF</a>
");
client.println("
");
client.println("
");
client.println("<a href=\"/?button2on\"\"> LED 2 ON</a>");
client.println("<a href=\"/?button1off\"\"> LED 2 OFF</a>
");
client.println("
");
client.println("
");
client.println("<a href=\"/?button3on\"\"> LED 3 ON</a>");
client.println("<a href=\"/?button3off\"\"> LED 3 OFF</a>
");
client.println("
");
client.println("
");
client.println("<a href=\"/?button4on\"\"> LED 4 ON</a>");
client.println("<a href=\"/?button4off\"\"> LED 4 OFF</a>
");
client.println("
");
client.println("
");
client.println("<a href=\"/?button5on\"\"> LED 5 ON</a>");
client.println("<a href=\"/?button5off\"\"> LED 5 OFF</a>
");
client.println("
");
client.println("
");
client.println("<a href=\"/?button6on\"\"> LED 6 ON</a>");
client.println("<a href=\"/?button6off\"\"> LED 6 OFF</a>
");
client.println("
");
client.println("
");
client.println("<a href=\"/?button7on\"\"> LED 7 ON</a>");
client.println("<a href=\"/?button7off\"\"> LED 7 OFF</a>
");
client.println("
");
client.println("
");
client.println("<a href=\"/?button8on\"\"> LED 8 ON</a>");
client.println("<a href=\"/?button8off\"\"> LED 8 OFF</a>
");
client.println("
");
client.println("</BODY>");
client.println("</HTML>");
delay(1);
//stopping client
client.stop();
//controls the Arduino if you press the buttons
if (readString.indexOf("?button1on") >0)
{
digitalWrite(PIN_LED[0], HIGH);
}
if (readString.indexOf("?button1off") >0)
{
digitalWrite(PIN_LED[0], LOW);
}
if (readString.indexOf("?button2on") >0)
{
digitalWrite(PIN_LED[1], HIGH);
}
if (readString.indexOf("?button2off") >0)
{
digitalWrite(PIN_LED[1], LOW);
}
if (readString.indexOf("?button3on") >0)
{
digitalWrite(PIN_LED[2], HIGH);
}
if (readString.indexOf("?button3off") >0)
{
digitalWrite(PIN_LED[2], LOW);
}
if (readString.indexOf("?button4on") >0)
{
digitalWrite(PIN_LED[3], HIGH);
}
if (readString.indexOf("?button4off") >0)
{
digitalWrite(PIN_LED[3], LOW);
}
if (readString.indexOf("?button5on") >0)
{
digitalWrite(PIN_LED[4], HIGH);
}
if (readString.indexOf("?button5off") >0)
{
digitalWrite(PIN_LED[4], LOW);
}
if (readString.indexOf("?button6on") >0)
{
digitalWrite(PIN_LED[5], HIGH);
}
if (readString.indexOf("?button6off") >0)
{
digitalWrite(PIN_LED[5], LOW);
}
if (readString.indexOf("?button7on") >0)
{
digitalWrite(PIN_LED[6], HIGH);
}
if (readString.indexOf("?button7off") >0)
{
digitalWrite(PIN_LED[6], LOW);
}
if (readString.indexOf("?button8on") >0)
{
digitalWrite(PIN_LED[7], HIGH);
}
if (readString.indexOf("?button8off") >0)
{
digitalWrite(PIN_LED[7], LOW);
}
readString="";
}
}
}
}
}