Sei sulla pagina 1di 8

Cdigo HTML:

<!doctype html>

<html> <!-- al comienzo de un archivo html siiempre se inicia con html-->

<head> <!--se abre la cabecera-->

<title><Led ON/OFF </title> <!--Ponemos el nombre de la pestaa-->

</head> <!--se cierra la cabecera-->

<body height="100%" width="100%"> <!--Comienza cuerpo, se establecen


parametros: Alto y largo.-->

<img src="https://scontent.fpbc1-2.fna.fbcdn.net/v/t34.0-
12/18763240_1344547262266444_1361534406_n.png?oh=54876028d45dd1aa11
fdb19ec51fff6e&amp;oe=59709A25"alt="TEC"width=10% height=10%
align="Right">

<img src="http://tecuruapan.edu.mx/redfocitec/Logos/11.png"alt="TEC"width=10%
height=10% align="left">

<center> <!--se centra el texto-->

<h1>INSTITUTO TECNOLOGICO DE ESTUDIOS SUPERIORES DE ZAMORA


</h1>
<h2>Docente:</h2>

<h1>Alejandro Mendez Navarro </h1>

<h2>Alumnos:</h2>

<h1>Martin Arellano Gomez<h1/>

<h1>Jesus Arellano Gomez<h1/>

<h1>Lampara ON/OFF</h1> <!--Se pone un titulo de nivel 1-->

<br /> <!--Espacio-->

<br /> <!--Espacio-->

Estado de la lampara: ON<br/> <!--Se escribe en el cuerpo y se deja el espacio


despues de ":" para poner el estado actual-->

<br /> <!--Espacio-->

<br /> <!--Espacio-->

<style type="text/css">

body{

background-image: url(https://encrypted-
tbn0.gstatic.com/images?q=tbn:ANd9GcSm-yF50AUlrs4L7fakeQ1-
P2CloSBPQ96W7UrZ39JzV3MOm_2VSUoWim0);

background-position : center;

background-repeat : no-repeat;

background-attachment : fixed;

background-size: cover;

-moz-background-size: cover;

-webkit-background-size: cover;

-o-background-size: cover;

</style>
<!--En la siguiente linea nos redireccionara a /LED=T, tipo de boton(envio)) ON-->

<input onclick="location.href='./?LED=T'" style="width:220px;height:75px"


type="submit" value="ON" />

<!--En la siguiente linea nos redireccionara a /LED=F, tipo de boton(envio)) OFF-->

<input onclick="location.href='./?LED=F'" style="width:220px;height:75px"


type="submit" value="OFF"/>

</center> <!--Se cierra el centrado-->

</body> <!--Se cierra el cuerpo de la pagina-->

</html> <!--Se cierra el archivo html-->

Circuito:
Cdigo ARDUINO:

#include <SPI.h> //Aqui incluimos la libreria SPI

#include <Ethernet.h> //Aqui incluimos la libreria Ethernet

byte mac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED}; //Declaracion de la direccion


MAC

IPAddress ip(192,168,0,6); //Declaracion de la IP

EthernetServer servidor(80); //Declaracion del puerto 80

int PIN_LED=8; //Aqui establecemos la variable PIN_LED como un valor entero

String readString=String(30); //lee los caracteres de una secuencia en una cadena.

//Los strings se representan como arrays de caracteres (tipo char)

String state=String(3);

void setup() {

Ethernet.begin(mac, ip); //Inicializamos con las direcciones asignadas

servidor.begin(); //inicia el servidor

pinMode(PIN_LED,OUTPUT);

digitalWrite(PIN_LED,LOW);

state="OFF";

void loop() {

//EthernetClient Crea un cliente que se puede conectar a


//una direccin especfica de Internet IP

EthernetClient cliente= servidor.available();

if(cliente) {

boolean lineaenblanco=true;

while(cliente.connected()) {

if(cliente.available()) {

char c=cliente.read();

if(readString.length()<30) {

readString.concat(c);

//Cliente conectado

//Leemos peticin HTTP caracter a caracter

//Almacenar los caracteres en la variable readString

if(c=='\n' && lineaenblanco) //Si la peticin HTTP ha finalizado

int LED = readString.indexOf("LED=");

if(readString.substring(LED,LED+5)=="LED=T") {

digitalWrite(PIN_LED,HIGH);

state="ON"; }

else if (readString.substring(LED,LED+5)=="LED=F") {

digitalWrite(PIN_LED,LOW);

state="OFF";

//Cabecera HTTP estndar


cliente.println("HTTP/1.1 200 OK");

cliente.println("Content-Type: text/html");

cliente.println(); //Pgina Web en HTML

cliente.println("<html>");

cliente.println("<head>");

cliente.println("<title>LED ON/OFF</title>");

cliente.println("</head>");

cliente.println("<body width=100% height=100%>");

cliente.println("<center>");

cliente.println("<h1>LED ON/OFF</h1>");

cliente.print("<br><br>");

cliente.print("Estado del LED: ");

cliente.print(state);

cliente.print("<br><br><br><br>");

cliente.println("<input type=submit value=ON style=width:200px;height:75px


onClick=location.href='./?LED=T\'>");

cliente.println("<input type=submit value=OFF style=width:200px;height:75px


onClick=location.href='./?LED=F\'>");

cliente.println("</center>");

cliente.println("</body>");

cliente.println("</html>");

cliente.stop();

//Cierro conexin con el cliente

readString="";

}
}

Potrebbero piacerti anche