[Dúvida] Ultimo estado do LED

Boa tarde galera...estou com uma dúvida com o estado de um led no meu arduino duemilanove + etherneth shield wiznet5100.

Eu consigo ligar e desligar o LED, mas se eu deixar o LED LIGADO e fechar o browser, quando eu abro o browser denovo, o LED apaga.

Alguém sabe me dizer como faço para deixar o LED em seu ultimo estado?

Obrigado.

vc esta bem confuso, eu fiz o código do post que vc apagou.
pra evitar de ler o estado do pino é mais facil fazer uma variavel de controle no caso aqui LEDON e FANON .
Eu não tenho como testar aqui apenas fiz o codigo e teste ai.

#include <String.h>
#include <Ethernet.h>
#include <SPI.h>

byte mac[] = {0xDE,0xAD,0xBE,0xEF,0xFE,0xED};
byte ip[] = {192,168,1,243};
byte gateway[] = {192,168,1,10};
byte subnet[] = {255,255,255,0};
Server server(80);
byte sampledata=50;
int ledPin = 4;
int fanPin = 5;
String readString = String(30);
boolean LEDON = false;
boolean FANON = false;

void setup(){
	Ethernet.begin(mac, ip, gateway, subnet);
	pinMode(ledPin, OUTPUT);
	pinMode(fanPin, OUTPUT);
	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();
				if (readString.length() < 30)
				{
					readString += c;
				}
				Serial.print(c);
				if (c == '\n') {
					if(readString.indexOf("L=1")>=0){
						digitalWrite(ledPin, HIGH);
						LEDON = true;
					}
					else if(readString.indexOf("L=0")>=0){
						digitalWrite(ledPin, LOW);
						LEDON = false;
					}
					if (c == '\n') {
						if(readString.indexOf("F=1") >=0){
							digitalWrite(fanPin, HIGH);
							FANON = true;
						}
						else if(readString.indexOf("F=0") >=0){							
							digitalWrite(fanPin,LOW);
							FANON = false;
						}
					}
					client.println("HTTP/1.1 200 OK");
					client.println("Content-Type: text/html");
					client.println();
					client.print("<html><body style=background-color:white>");
					client.println("<center>");
					client.println("<h1>Casa Inteligente</h1><hr>");
					client.println("<center>");
					client.println("<h2>Luz do Quintal</h2>");
					client.print("<a href='L=1'>Ligar</a> |  <a href='L=0'> Desligar </a> | Status :");
					if(LEDON){
						client.print("ON") ;
					}else if(!releAtivado) {
						client.print("OFF") ;
					}
					client.println("<h2>Ar do Quarto</h2>");
					client.print("<a href='F=1'>Ligar</a> |  <a href='F=0'> Desligar </a> | Status :");
					if(FANON){
						client.println("ON") ;
					}else if(!releAtivado) {
						client.println("OFF") ;
					}
					client.println("<hr>");
					client.println("</body></html>");
					readString="";
					client.stop();
				}
			}
		}
	}
}

Então Rafael,

você viu o ultimo codigo, mas se liga nesse:

Adicionei 1 termistor para medir a temperatura... TEMPERATURA OK(funcionou direitinho).
Porém, quando eu marco o checkbox e aplico a LUZ APAGA. Quando eu deixo desmarcada e aplico, a luz acende. Queria que fosse ao contrario.

#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 }; // IP
byte gateway[] = {
192, 168, 1, 10 }; // roteador
byte subnet[] = {
255, 255, 255, 0 }; //Subnet
Server server(80); //Porta
byte sampledata=50;//some sample data - outputs 2 (ascii = 50 DEC)

int ledPin = 4; // Pino do Led
int analogPin = 0; //Pino Termistor
int tempc= 0, tempf=0,tempk=0;
int samples[8];
int i;
String readString = String(30);
boolean LEDON = false; //LED status flag

void setup(){
Ethernet.begin(mac, ip, gateway, subnet);
pinMode(ledPin, OUTPUT);
Serial.begin(9600); //enable serial datada print
}
void loop(){

Client client = server.available();// Cria uma conexao cliente
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;
}

for(i = 0; i<=7 ;i++){
samples = ( 5.0 * analogRead(analogPin) * 100.0) / 1024.0;
_ tempc = tempc + samples*; // somando os 8 valores lidos*_
* }*
* tempc = tempc/8.0; // tirando a media dos 8 valores*
_ tempf = (tempc * 9)/ 5 + 32; // converte para fahrenheit_
* tempk= tempc+273; // converte para Kelvin*
* delay(100);*
* //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 ON*
* digitalWrite(ledPin, HIGH); // set the LED off*
* LEDON = true;*
* }*
* else if(readString.indexOf("L=0") >=0){*
* //led has to be turned OFF*
* digitalWrite(ledPin, LOW); // 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

");*

* client.println("");*
* client.println("");*
* client.println("

");*
* client.println("");*
* client.println("

Luz do Quintal

");*

* //controlling led via checkbox*
* 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("Temperatura C:"); //Mostra as temperaturas em C F e K*
* client.println(tempc);*
* client.println("\t");*
* client.println("Temperatura F:");*
* client.println(tempf);*
* client.println("\t");*
* client.println("Temperatura K:");*
* client.println(tempk);*
* client.println("\n");*
* client.println("");*

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

esse esquema de form fica bonito mas só ocupa memória... se eu fosse vc deixa html puro.

vc tem q inverter a parte que lê

if(readString.indexOf("L=1") >=0)
{
//led has to be turned ON
digitalWrite(ledPin, LOW); // set the LED off
LEDON = false;
}else if(readString.indexOf("L=0") >=0){
digitalWrite(ledPin, HIGH); // set the LED on
LEDON = true;
}

Consegui acionar uma ventoinha depois que a temperatura atinge mais que 33 Graus Celcius.

Porém, coloquei o esquema de leitura LEDON da forma que você me passou e fica dando problema.

Eu quero acionar o LED da seguinte forma:

seleciono o checkbox, aplico, o LED liga, e o status fica ON.
se eu deixar o checkbox desmarcado e aplicar, o LED desliga, e o status fica OFF.

O código que postarei aqui em baixo está funcionando, porém está com as partes de LEDON, LOW, HIGH todo invertido.
Fora que mesmo se eu tiver ligado o LED, se eu fechar o browser e abrir novamente com o IP do ethernet shield, o LED apaga, sendo que eu queria que ele mantesse o estado que eu tinha deixado.

#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 }; // IP
byte gateway[] = {
192, 168, 1, 10 }; // roteador
byte subnet[] = {
255, 255, 255, 0 }; //Subnet
Server server(80); //Porta
byte sampledata=50;//some sample data - outputs 2 (ascii = 50 DEC)

int ledPin = 4;//Pino do Led
int fanPin = 5;// Pino do Fan
int analogPin = 0; //Pino Termistor
int tempc= 0, tempf=0,tempk=0;
int samples[8];
int i;
String readString = String(30);
boolean LEDON = false;
boolean FANON = false;//LED status flag

void setup(){
Ethernet.begin(mac, ip, gateway, subnet);
** pinMode(ledPin, OUTPUT);**
pinMode(fanPin, OUTPUT);
Serial.begin(9600); //enable serial datada print
}
void loop(){

Client client = server.available();// Cria uma conexao cliente
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;
}

for(i = 0; i<=7 ;i++){
samples = ( 5.0 * analogRead(analogPin) * 100.0) / 1024.0;
_ tempc = tempc + samples*; // somando os 8 valores lidos*_
* }*
* tempc = tempc/8.0; // tirando a media dos 8 valores*
_ tempf = (tempc * 9)/ 5 + 32; // converte para fahrenheit_
* tempk= tempc+273; // converte para Kelvin*
* delay(100);*

* if (tempc >= 33){*
* digitalWrite(fanPin, LOW);*
* FANON = true;*
* }*
* else{*
* digitalWrite(fanPin, HIGH);*
* FANON = false;*
* }*
* //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

");*

* client.println("");*
* client.println("");*
* client.println("

");*
* client.println("");*
* client.println("

Luz do Quintal

");*

* //controlling led via checkbox*
* 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("Temperatura C:"); //Mostra as temperaturas em C F e K*
* client.println(tempc);*
* client.println("\t");*
* client.println("Temperatura F:");*
* client.println(tempf);*
* client.println("\t");*
* client.println("Temperatura K:");*
* client.println(tempk);*
* client.println("\n");*
* client.println("");*

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

Se alguma outra pessoa puder ajudar, serei muito grato!

:smiley: