TinyWebServer BlinkLed - ampliare i comandi e attivare 6 o + led

Questa è una versione intermedia. Ci metto 200 anni a ripulirlo tutto. Guardalo bene e chiedimi di volta in volta cosa non capisci.

#include <LED.h>
#include <SPI.h>
//#include <WString.h>
#include <Ethernet.h>
#include <avr/pgmspace.h>

//--------Sensore Digitale Temperatura e Umidità


#define DHT11_PIN 4      // ADC0

byte read_dht11_dat()
{
  byte i = 0;
  byte result=0;
  for(i=0; i< 8; i++)
  {
    while(!(PINC & _BV(DHT11_PIN)));  // wait for 50us
    delayMicroseconds(30);
    if(PINC & _BV(DHT11_PIN)) 
      result |=(1<<(7-i));
    while((PINC & _BV(DHT11_PIN)));  // wait '1' finish
    }
    return result;
}
//--------Fine Sensore T&H


//prog_char string_0[] PROGMEM = "<form><html><body><h2>Controllo Salotto</h2><font size= 4><form method=GET>";
//prog_char string_0[] PROGMEM = "<html><body><h2>Controllo Salotto</h2><font size= 4><form method=GET>";
prog_char string_0[] PROGMEM = "";
prog_char string_1[] PROGMEM = "<tr><td><input type=submit name=b1 value=Luce_1></td><td>";
prog_char string_2[] PROGMEM = "<tr><td><input type=submit name=b2 value=Luce_2></td><td>";
prog_char string_3[] PROGMEM = "<tr><td><input type=submit name=b3 value=Luce_3></td><td>";
prog_char string_4[] PROGMEM = "<tr><td><input type=submit name=b4 value=AUX></td><td>";
prog_char string_5[] PROGMEM = "<tr><td><input type=submit name=Up value=Alza&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp></td><td>";
//<tr><td><input type=submit name=Stop value=Stop&nbsp&nbsp&nbsp></td><td>";
prog_char string_6[] PROGMEM = "<tr><td><input type=submit name=Down value=Abbassa></td><td>";
prog_char string_7[] PROGMEM = "</form>";
//prog_char string_7[] PROGMEM = "</form>";
prog_char string_8[] PROGMEM = "<img src='data:image/gif;base64,R0lGODlhEAAQALMAABgDBKyqrHV2dZUCBOnf3X8CBPsCBCIhIvwWFPz9/L27vfbu7BUSE/kSFPwgILS1tCH5BAAAAAAALAAAAAAQABAAAwR5MEnJqp04sSO6eM/BZFwHnECgKMfEmEAjG6c6JhxgOEtCNAYaS2Pi+YDB1KMiiPUIjmCwAFAwY76odEAliJoNAkIa5AK8jIAOuTUvRA812TAwE944ha5cL1DxGgpqAH5+JwQaEwcrgwAMdzgZGysElW83GRobB5wZEQA7'/>";
//prog_char string_8[] PROGMEM = "<img src=data:image/gif;base64,R0lGODlhEAAQAKIAAAD/AACGAISGhMbHxv///wAAAAAAAAAAACwAAAAAEAAQAAADUEiq1b6QNEHFGC2W6srFyyY0QAk0V8GM5WJ6qlgA7ptuc20GME4TplKAJ/EBg4BhDIYUKosp5JAokWB2U6LKiilkM1XGpxPSeAYQcKRIhiQAADs= alt=Acceso ></td><td>";
prog_char string_9[] PROGMEM = "<img src=data:image/gif;base64,R0lGODlhEAAQAKIAAP////f398DAwICAgAAAAAAAAAAAAAAAACwAAAAAEAAQAAADTRiq1L4wtEGHEC2S6sjFyzY0H+aB0ngB7OcRqcoC5Tl5cymot9CWFAKgR9MFhy/dhYO8nD7MoQQDrYykU5O1wYIxXI6ZN3SaISPkTiQBADs= alt=Spento ></td><td>";
prog_char string_10[] PROGMEM = "";
//prog_char string_10[] PROGMEM = "</form></body></html>";
prog_char string_11[] PROGMEM = "";
//prog_char string_11[] PROGMEM = "<meta http-equiv=refresh content=5 >";
prog_char string_12[] PROGMEM = "";
prog_char string_13[] PROGMEM = "Sensore Finestra";

PROGMEM const char *string_table[] = // change "string_table" name to suit
{
string_0,
string_1,
string_2,
string_3,
string_4,
string_5,
string_6,
string_7,
string_8,
string_9,
string_10,
string_11,
string_12,
string_13,
};

char buffer[400]; // make sure this is large enough for the largest string it must hold

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 4 };
byte gateway[] = { 192, 168, 1, 1 };
byte subnet[] = { 255, 255, 255, 0 };

String inString = String(50);

Server server(8000);

LED led1 = LED(3);
LED led2 = LED(4);
LED led3 = LED(5);
LED led4 = LED(6);

LED led5 = LED(1);
LED led6 = LED(2);
//LED led7 = LED(8);
//LED led8 = LED(9);

String msg="";
//int tam=0;
int st1=9,st2=9,st3=9,st4=9,st5=9,st6=9;//,st7=9,st8=9;
//--------------------------------------------------
//int outPin = 9; // pin attuatore
//char link[]="http://www.giannifavilli.it"; //link
String readString; //string
boolean LEDON = false; // flag status attuatore
 
/*termistore
float temp; // variabile da calcolare
float tempPin = 2;   // pin analogico IN temperature sensor*/
int tempreg = 22; // temperatura di controllo in celsius
/*end termistore*/
 
/*fotoresistore*/
int light; // variabile da calcolare
int photoresistor = 3; // pin analogico IN fotoresistore
/*end fotoresistore*/

//-----------------------------------------------------
// Sensore Infrarossi
int SensoreIn = 7;
//int SensoreOut = 6;
int valSens;
boolean SensoreToggle=true;
//---------------------------------------
//Sensore Magnetico
int Finestra = 8;
int valFin;

void setup()
{
//----Sensore T&H
 DDRC |= _BV(DHT11_PIN);
 PORTC |= _BV(DHT11_PIN);
 
//-----Fine Sensore T&H
  
Serial.begin(9600);
Ethernet.begin(mac, ip,gateway,subnet);
server.begin();
Serial.println("Serial READY");
Serial.println("Ethernet READY");
Serial.println("Server READY");

  pinMode(3,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
//---------------------
//pinMode(outPin, OUTPUT);
//pinMode(ledPinlux, OUTPUT);

pinMode(Finestra, INPUT);
pinMode(SensoreIn, INPUT);
//pinMode(SensoreOut, OUTPUT);

//---------------------
}

void loop()
{
  
//----Sensore T&H
  byte dht11_dat[5];
  byte dht11_in;
  byte i;// start condition
	 // 1. pull-down i/o pin from 18ms
  PORTC &= ~_BV(DHT11_PIN);
  delay(18);
  PORTC |= _BV(DHT11_PIN);
  delayMicroseconds(40);
  DDRC &= ~_BV(DHT11_PIN);
  delayMicroseconds(40);
  
  dht11_in = PINC & _BV(DHT11_PIN);
  if(dht11_in)
  {
 //   Serial.println("dht11 start condition 1 not met");
    DDRC |= _BV(DHT11_PIN);
    PORTC |= _BV(DHT11_PIN);

    return;
  }
  delayMicroseconds(80);
  dht11_in = PINC & _BV(DHT11_PIN);
  if(!dht11_in)
  {
//    Serial.println("dht11 start condition 2 not met");
    DDRC |= _BV(DHT11_PIN);
    PORTC |= _BV(DHT11_PIN);

    return;
  }
  
  delayMicroseconds(80);// now ready for data reception
  for (i=0; i<5; i++)
  {dht11_dat[i] = read_dht11_dat();}

  DDRC |= _BV(DHT11_PIN);
  PORTC |= _BV(DHT11_PIN);
//  byte dht11_check_sum = dht11_dat[0]+dht11_dat[1]+dht11_dat[2]+dht11_dat[3];// check check_sum
//  if(dht11_dat[4]!= dht11_check_sum)
//  {
//    Serial.println("DHT11 checksum error");
//  }
//  Serial.print("Current humdity = ");
//  Serial.print(dht11_dat[0], DEC);
//  Serial.print(".");
//  Serial.print(dht11_dat[1], DEC);
//  Serial.print("%  ");
//  Serial.print("temperature = ");
//  Serial.print(dht11_dat[2], DEC);
//  Serial.print(".");
//  Serial.print(dht11_dat[3], DEC);
//  Serial.println("C  ");
  
//----Fine Sensore T&H
  
//-------------------Sensore Magnetico Finestra e Infrarossi
  valFin = digitalRead(Finestra);
  valSens = digitalRead(SensoreIn);
  
   

  //--------------------------------
  /*inizio calcolo temperatura*/
  //temp = ((5 * analogRead(tempPin) * 100.0 ) / 1024); // Codice ottimizzato
 // temp = analogRead(tempPin);           //read the value from the sensor
//  temp = (5.0 * temp * 100.0)/1024;
 
  /*
  (grazie giulio400 e jumpjack)
  volt = ( analogRead(tempPin) * 5) / 1024; // calcolo il valore letto e lo trasformo in valore di tensione
  temp = (volt - 0.5) * 100; // conversione MCP9700A
  */
  /*fine calcolo temperatura*/
 
  /*inizio luce*/
  light = analogRead(photoresistor);
  light = constrain(light, 0, 1023); // limiti dei valori tra 0 e 100
  //light = map(light, 0, 150, 255, 0);
  /*fine luce*/
 
 //-------------------Interruttore presenza
if (SensoreToggle == true){
  if (valSens == HIGH){
  //digitalWrite(SensoreOut, HIGH);
  led1.on();
  if(led1.getState()) st1=8;
  else st1=9;
  }
  else {    
//  digitalWrite(SensoreOut, LOW);   
  led1.off(); 
  
  if(led1.getState()) st1=8;
  else st1=9;  
  } 
}  
//--------------------------Start Client
Client client = server.available();

int led=0;
if (client) {

// an http request ends with a blank line
boolean current_line_is_blank = true;
while (client.connected()) {

if (client.available()) {

char c = client.read();
// if we've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so we can send a reply
if (inString.length() < 50){
inString.concat(c);

}
if (c == '\n' && current_line_is_blank) {
  
/*-------------------------------
  Serial.print(readString);
        if(readString.indexOf("L=1") > 0) {// lettura del valore se il LED si deve accendere
          // il led sarà acceso
          digitalWrite(outPin, HIGH); // accendo il led
          LEDON = true;
          Serial.print("ON pin ");
          Serial.println(outPin);
          }
          else
          {
          //il led sarà spento
          digitalWrite(outPin, LOW); //sengo il led
          LEDON = false;
          Serial.print("OFF pin ");
          Serial.println(outPin); }
//-------------------------------------*/
  
/* if(inString.indexOf("b1")>0)
{

led1.toggle();
if(led1.getState()) st1=8;
else st1=9;
led=1;
 }*/

  
 // else {led1.on();}