Hi guys,
This is the code of my project.. I found some of it on the net.. But I need to know what each line of this code does..
for ex.
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
What does it mean??
client.println("HTTP/1.1 200 OK");
Why this line?
#include <String.h>
#include <SPI.h>
#include <Ethernet.h>
/*
Circuit:
* Arduino MEGA ADK
* Arduino Ethernet shield
* 2 LEDs connected to GND and 5V via 2 resistors 230 Ohm
* 2 channel relay board connected to GND, 5V, and digital pin 2
*/
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //mac address
byte ip[] = { 192, 168, 0, 27 }; // ip address in LAN
EthernetServer server(80); //server port
int ledPin = 2; // LED pin
boolean ledOn = false; //LED status
String stringa; //string
char mex[]=("<marquee width='300' height='30' style='font-size: 20pt; font-family: Vineta BT; color= #FF0000; font-weight: bold'> DEVICE CONTROL from Internet </marquee>");
void setup()
{
Ethernet.begin(mac, ip);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
EthernetClient client = server.available();
boolean flag;
if (client)
{
flag=true;
while (client.connected())
{
if (client.available())
{
char c = client.read();
stringa.concat(c);
if (c == '\n' && flag)
{
Serial.print(stringa);
if(stringa .indexOf("L=1") > 0)
{
digitalWrite(ledPin, HIGH);
ledOn = true;
}
else
{
digitalWrite(ledPin, LOW);
ledOn = false;
}
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.print("<html><head><title>ARDUINO WEB Control </title><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' ></head><body>");
//body
client.println("<div style='width:200px; height:600px;'>");
client.print(mex);
client.println("<hr />");
client.print("<h2>DEVICE status: </h2>");
if (ledOn)
{
client.println("<span style='color:green'><h2>ON</h2></span>");
}
else
{
client.println("<span style='color:red'><h2>OFF</h2></span>");
}
client.println("<h1>DEVICE control</h1>");
client.print("<h2><a href='/?L=1'><span style='color:green'>Turn ON</a> | <a href='/?L=0'><span style='color:red'>Turn OFF</a></h2>");
client.println("<hr />");
client.print("Freeman | Arduino Lover");
client.println("<hr />");
client.println("</body></html>");
stringa="";
client.stop();
}
}
}
}
}