help with Duemilanove + Ethernet W5100

Hello Guys,

Sorry, my English don't is very well. But I try.
I'm have issues to do torn ON and OFF two LEDs.
When I turn ON ledPin 4 and I want turn ON ledPin 5, the ledPin 4 turn OFF.
I know that my code have some error.

Does they to help me?

The code whith ONE LED(It Works):

#include <String.h>
#include <Ethernet.h>
#include <SPI.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = {
192, 168, 1, 243 }; // Endereco IP
byte gateway[] = {
192, 168, 1, 10 }; // IP roteador
byte subnet[] = {
255, 255, 255, 0 }; //Mascara
Server server(80); //Porta
byte sampledata=50; //some sample data - outputs 2 (ascii = 50 DEC)
int ledPin = 4; // Pino do Led utilizado
//char link[]="http://192.168.1.243/"; //link data
String readString = String(30); //string for fetching data from address
boolean LEDON = false; //LED status flag
void setup(){
//iniciar Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
//Set pin 4 to output
pinMode(ledPin, OUTPUT);
//enable serial datada print
Serial.begin(9600);
}
void loop(){
// Cria uma conexao cliente
Client client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 30)
{
//store characters to string
readString += c;
}
//output chars to serial port
Serial.print(c);
//if HTTP request has ended
if (c == '\n') {
//lets check if LED should be lighted
if(readString.indexOf("L=1") >=0)
{
//led has to be turned OFF
digitalWrite(ledPin, LOW); // set the LED off
LEDON = true;
}
else{
//led has to be turned ON
digitalWrite(ledPin, HIGH); // set the LED on
LEDON = false;
}
// now output HTML data starting with standart header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
//set background to yellow
client.print("");
//send first heading
client.println("");
client.println("

Casa Inteligente

");
//output some sample data to browser
//client.println("Sample data: ");
//client.print(sampledata);//lets output some data
//drawing simple table
//client.println("Simple table: ");
//printing some link
client.println("");
client.println("");
client.println("
");
client.println("");
client.println("

Luz do Quintal

");
//controlling led via checkbox
//address will look like http://192.168.1.243/?L=1 when submited
client.println("LUZ
");
client.println("
(1=ON / 0=OFF)
");
//printing LED status
client.print("Status: ");
if (LEDON)
client.println("ON");
else
client.println("OFF");
client.println("");
client.println("
");
client.println("");
//clearing string for next read
readString="";
//stopping client
client.stop();
}
}
}
}
}

And the code whith problem(usin two leds(led and fan in my code):

#include <String.h>
#include <Ethernet.h>
#include <SPI.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = {
192, 168, 1, 243 }; // Endereco IP
byte gateway[] = {
192, 168, 1, 10 }; // IP roteador
byte subnet[] = {
255, 255, 255, 0 }; //Mascara
Server server(80); //Porta
byte sampledata=50; //some sample data - outputs 2 (ascii = 50 DEC)
int ledPin = 4;
int fanPin = 5; // Pino do Led utilizado
//char link[]="http://192.168.1.243/"; //link data
String readString = String(30); //string for fetching data from address
boolean LEDON = false;//LED status flag
boolean FANON = false;

void setup(){
//iniciar Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
//Set pin 4 to output
pinMode(ledPin, OUTPUT);
pinMode(fanPin, OUTPUT);
//enable serial datada print
Serial.begin(9600);
}
void loop(){
// Cria uma conexao cliente
Client client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 30)
{
//store characters to string
readString += c;
}
//output chars to serial port
Serial.print(c);
//if HTTP request has ended
if (c == '\n') {
//lets check if LED should be lighted
if(readString.indexOf("L=1") >=0)
{
//led has to be turned OFF
digitalWrite(ledPin, LOW); // set the LED off
LEDON = true;
}
else{
//led has to be turned ON
digitalWrite(ledPin, HIGH); // set the LED on
LEDON = false;
}

if (c == '\n') {
//lets check if LED should be lighted
if(readString.indexOf("F=1") >=0)
{
//led has to be turned OFF
digitalWrite(fanPin, LOW); // set the LED off
FANON = true;
}
else{
//led has to be turned ON
digitalWrite(fanPin, HIGH); // set the LED on
FANON = false;
}
}
// now output HTML data starting with standart header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
//set background to yellow
client.print("");
//send first heading
client.println("");
client.println("

Casa Inteligente

");
//output some sample data to browser
//client.println("Sample data: ");
//client.print(sampledata);//lets output some data
//drawing simple table
//client.println("Simple table: ");
//printing some link
client.println("");
client.println("");
client.println("");
client.println("
");
client.println("");
client.println("

Luz do Quintal

");
//controlling led via checkbox
//address will look like http://192.168.1.243/?L=1 when submited
client.println("LUZ
");
client.println("
(1=ON / 0=OFF)
");
//printing LED status
client.print("Status: ");
if (LEDON)
client.println("ON");
else
client.println("OFF");
client.println("");
client.println("
");
client.println("");
client.println("

Ar do Quarto

");
client.println("Ar-Condionado
");
client.println("
(1=ON / 0=OFF)
");
client.print("Status: ");
if (FANON)
client.println("ON");
else
client.println("OFF");
client.println("

");
client.println("");
//clearing string for next read
readString="";
//stopping client
client.stop();
}
}
}
}
}

Please, help me... :slight_smile: