[ethernet] controlling led with automatic and manual mode

i’m trying to control led in automatic and manual mode… and make monitoring+controlling system via web using ethernet shield

in automatic mode, the output of led depends on sensor reading
if (sensor HIGH) {then led HIGH} else { then led LOW}

in manual mode, the output led does’nt depend on sensor reading anymore… but it depends on “set turn” button clicking which is only available when manual mode activated.
to activate the manual mode, the “toggle” button must be clicked first…if the “toggleoff” button clicked, that would set back to automatic mode

well…the automatic mode is fine… the problem is the manual mode… it still does’nt work
here is my code… please check it out… which part is wrong ?
thanks

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


byte mac[] = { 0x54, 0x55, 0x58, 0x10, 0x00, 0x24 };  //  MAC 
byte ip[]  = { 167, 205, 45, 177 };                  // IP-Adress
byte gateway[] = { 167, 205, 1, 1 };                // Gateway
byte subnet[]  = { 255, 255, 255, 0 };

Server server(80);
int Pir1 = 2;  //sensor pir
int Led1 = 12;  //  led output
boolean Pir1ON, Led1ON, Toggle1ON = false; 
int PirState1 = 0;

String readString = String(100);      // string for fetching data from address

void setup(){
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
 
pinMode(Pir1, INPUT);
pinMode(Led1, OUTPUT);
 }

void loop(){
int PirState1 =digitalRead(Pir1); //reading pir sensor status
int LedState1 = digitalRead(Led1); // reading led status

// automatic mode

if(PirState1 == HIGH){  
  Pir1ON = true;
 digitalWrite(Led1, HIGH); 
 }
  else{
    Pir1ON = false;
        digitalWrite(Led1, LOW);
}

 if(LedState1 == HIGH){
 Led1ON = true;
 }
 else{
   Led1ON = false;
 }

// Create a client connection
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() < 100) {

//store characters to string

readString = readString + c; 

}

Serial.print(c);  //output chars to serial port

if (c == '\n') {  //if HTTP request has ended


// manual mode when "toggle" button pressed
//maybe this part is the problem

if(readString.indexOf("1=set+toggle") > -1) { 
  Toggle1ON= true;
  if(LedState1 == HIGH){
  if(readString.indexOf("1=set+turn") > -1) {
    digitalWrite( Led1, LOW);
    Led1ON = false;
   }} else {
      if(readString.indexOf("1=set+turn") > -1) {
    digitalWrite( Led1, HIGH);
    Led1ON = true;
  }
   }
}

// ended manual mode   
if(readString.indexOf("1=toggleoff") > -1){
  Toggle1ON= false;
}

//--------------------------HTML------------------------
client.println("HTTP/1.1 200 OK");

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

client.println();

client.print("<html><head>");

client.print("<title>Arduino Webserver </title>");
client.println("<meta http-equiv=\"refresh\" content=\"2\">");

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

client.print("<body bgcolor='white'>");


client.println("
<hr />");

client.println("<h1><div align='center'><font color='#2076CD'>Arduino Webserver</font color></div></h1>");


client.println("<div align='center'>");
client.println("<table border=5>");

// display manual mode (when "toggle" button pressed)
if(Toggle1ON){
  if(Pir1ON){   
client.println("<tr>");
client.println("<td bgcolor='red'>Sensor 1</td> <td bgcolor='yellow'>ON</td>");
if(Led1ON){
  client.println("<td bgcolor='white'>Led 1</td> <td bgcolor='yellow'>ON</td>");
  }
  else{
  client.println("<td bgcolor='white'>Led 1</td> <td bgcolor='red'>OFF</td>");
 }
 client.println("<td align='middle'><form method=get><input type=submit name=1 value='set turn'></form></td><td align='middle'><form method=get><input type=submit name=1 value='toggleoff'></form></td>");
 client.println("</tr>");
}
else{
  client.println("<tr>");
  client.println("<td bgcolor='white'>Sensor 1</td><td bgcolor='red'>OFF</td><td bgcolor='white'>Led 1</td> <td bgcolor='red'>OFF</td><td align='middle'><form method=get><input type=submit name=1 value='set turn'><td align='middle'><form method=get><input type=submit name=1 value='toggleoff'></form></td>");
  client.println("</tr>");
  }
}

// display automatic mode
else{
if(Pir1ON){   
client.println("<tr>");
client.println("<td bgcolor='red'>Sensor 1</td> <td bgcolor='yellow'>ON</td>");
if(Led1ON){
  client.println("<td bgcolor='white'>Led 1</td> <td bgcolor='yellow'>ON</td>");
    }
  else {
  client.println("<td bgcolor='white'>Led 1</td> <td bgcolor='red'>OFF</td>");
 }
 client.println("<td>set turn</td><td align='center'><form method=get><input type=submit name=1 value='set toggle'></form></td>");
 client.println("</tr>");
}
else{
  client.println("<tr>");
  client.println("<td bgcolor='white'>Sensor 1</td><td bgcolor='red'>OFF</td><td bgcolor='white'>Led 1</td><td bgcolor='red'>OFF</td> <td align='center'>set turn</td> <td align='center'><form method=get><input type=submit name=1 value='set toggle'></form></td>");
  client.println("</tr>");
  }
}


client.println("</table>");
client.println("</div>");

client.println("</body></html>");

//clearing string for next read
readString="";

//stopping client
delay(1);
client.stop();
}}}} 

}
pinMode(Led1, OUTPUT);
 }

void loop(){
int PirState1 =digitalRead(Pir1); //reading pir sensor status
int LedState1 = digitalRead(Led1); // reading led status

You're reading from an output pin? Got a poor memory? You should keep track of whether you have turned the light on, or not.

it still does'nt work

Telling us what you expect, and what actually happens, and how that differs from what you want, is a whole lot more productive.

PaulS: You're reading from an output pin? Got a poor memory? You should keep track of whether you have turned the light on, or not. ..............

Telling us what you expect, and what actually happens, and how that differs from what you want, is a whole lot more productive.

reading the output pin to ensure the current status of led..

the problem is when the system running on manual mode ("set toggle" pressed), i want led output doesn't depend on sensor status anymore..

when i press "set toggle" i want to keep (toggled) the current led pin status. if led current status is HIGH, i want to keep led ON even the sensor reading is LOW...

when i press the "set turn" button, i want led output OFF/ON depends on the current status of led pin (OFF if led current status pin is HIGH, or ON if led pin current status is LOW)

what actually happens : it seems led output still depends on sensor status even i pressed "set toggle" button when i press "set toggle" button, it doesn't keep the current led pin status (except when led current status is LOW) when i press "set turn"button, it doesn't change led output