controling outlets with delays,try to multitask them,need help

Hello i am jim and i create a programm that contolling some outlets from web page(2outputs open instant,2 with delay and 1 opens by voltage levels)
The problem that i got is that when the 2 outputs are on delay the others w8ing for them to end so i want to somehow multitask them like (if i want to open 1 instant output 1 delay output and the fade one, instantly opens output 1 and fade output without w8 for the delay output to open)

my code is this

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

  byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };          //physical mac address
  byte ip[] = { 192, 168, 1, 240 };			        // ip in lan
  byte gateway[] = { 192, 168, 1, 1 };			        // internet access via router
  byte subnet[] = { 255, 255, 255, 0 };                         //subnet mask
  Server server(5210);                                            //server port
  int speakerPin = 2; // speaker connected to digital pin 9 

  const int analogOutPin = 5;
  int sensorValue = 0;
  int outputValue = 0;

  int ledPin6 = 6;                                              // LED pin
  int ledPin7 = 7;
  int ledPin8 = 8;
  int ledPin9 = 9;  
  int inputPin3 = 3;                                            // choose the input pin (for a pushbutton)
  int val = 0;                                                  // variable for reading the pin status


  boolean LED1ON = false;                                       //LED status flag
  boolean LED2ON = false;
  boolean LED3ON = false;
  boolean LED4ON = false;
  boolean F1ON = false;
  boolean F2ON = false;
  boolean F3ON = false;
  boolean F4ON = false;
  boolean F5ON = false;
  boolean F6ON = false;
  boolean F7ON = false;
  boolean F8ON = false;
  boolean F9ON = false;
  boolean F10ON = false;

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

  
void setup(){
  Ethernet.begin(mac, ip, gateway, subnet);
  pinMode(ledPin6, OUTPUT);  
  pinMode(ledPin7, OUTPUT);
  pinMode(ledPin8, OUTPUT);
  pinMode(ledPin9, OUTPUT);
  pinMode(inputPin3, INPUT);                                    // declare pushbutton as input
  Serial.begin(9600);
  pinMode(speakerPin, OUTPUT);                                  // sets the speakerPin to be an output 

}

plz help i am very confused. :slight_smile:

void loop(){


  


  Client client = server.available();
  if (client) {
    while (client.connected()) {
   if (client.available()) {
    char c = client.read();
     Serial.print(c);
     if (readString.length() < 30) 
      {
        readString.concat(c);                                    //store characters to string 
      }  
        if (c == '\n') {                                         //if HTTP request has ended
          
          ledstatus();                                           //LED Status Sub
          htmlcontent();                                         //LED Html Content Sub
          
          readString="";                                         //clearing string for next read
          client.stop();                                         //stopping client
          delay(100);
         }
       }
     }
   }
 }     


void htmlcontent(){
    Client client = server.available();
    client.println("HTTP/1.1 200 OK");                           // now output HTML data starting with standart header
    client.println("Content-Type: text/html");
    client.println();
    client.print("<body>");
    client.print("LED ON/OFF");
    client.println("<form method=get name=LED>");
    client.println("<INPUT TYPE=CHECKBOX NAME=L1 value=1 >L1
");

    client.println("<INPUT TYPE=CHECKBOX NAME=L2 value=1 >L2
");
    client.print("LED DELAY ON 
 ");
    client.println("<INPUT TYPE=CHECKBOX NAME=D1 value=1 >D1
");

    client.println("<INPUT TYPE=CHECKBOX NAME=D2 value=1 >D2<P>"); 
    client.print("LED FADE 
 ");
    client.println("<input type=checkbox name=F1 value=1>10%

");
    client.println("<input type=checkbox name=F2 value=1>20%

");
    client.println("<input type=checkbox name=F3 value=1>30%

");
    client.println("<input type=checkbox name=F4 value=1>40%

");
    client.println("<input type=checkbox name=F5 value=1>50%

");
    client.println("<input type=checkbox name=F6 value=1>60%

");
    client.println("<input type=checkbox name=F7 value=1>70%

");
    client.println("<input type=checkbox name=F8 value=1>80%

");
    client.println("<input type=checkbox name=F9 value=1>90%

");
    client.println("<input type=checkbox name=F10 value=1>100%

");

    client.println("<INPUT TYPE=SUBMIT VALUE=submit>");
    client.println("</FORM>");
    client.print("Outlet statusL1: "); 
        if (LED1ON)
           client.println("ON"); 
        else
           client.println("OFF");    
    client.print("
 Outlet statusL2: ");
        if (LED2ON)
           client.println("ON"); 
        else
           client.println("OFF"); 
    client.print("
 Outlet statusD1: ");
        if (LED3ON)
           client.println("ON"); 
        else
           client.println("OFF");  
    client.print("
 Outlet statusD2: "); 
        if (LED4ON)
           client.println("ON"); 
        else
           client.println("OFF");
    client.println("

");
    

    client.print("Outlet status FADE: "); 
        if (F1ON)
           client.println("10%"); 
        else if (F2ON)
           client.println("20%");
        else if (F3ON)
           client.println("30%");
        else if (F4ON)
           client.println("40%");
        else if (F5ON)
           client.println("50%");
        else if (F6ON)
           client.println("60%");
        else if (F7ON)
           client.println("70%");
        else if (F8ON)
           client.println("80%");
        else if (F9ON)
           client.println("90%");
        else if (F10ON)
           client.println("100%");
        else
           client.println("0%");



  
    client.println("</body></html>");
}
void ledstatus(){
  if(readString.indexOf("L1=1")>0)                                   //lets check if LED should be lighted
      {
       digitalWrite(ledPin6, HIGH);                                  // set the LED on
       LED1ON = true;
       }else{ 
       digitalWrite(ledPin6, LOW);                                   // set the LED OFF
       LED1ON = false;             
       }
  if(readString.indexOf("L2=1")>0) 
      {
       digitalWrite(ledPin7, HIGH);    
       LED2ON = true;
       }else{
       digitalWrite(ledPin7, LOW);    
       LED2ON = false;             
       }
  if(readString.indexOf("D1=1")>0) 
      {
       delay(2000); 
       digitalWrite(ledPin8, HIGH);    
       LED3ON = true;
       }else{
       digitalWrite(ledPin8, LOW);    
       LED3ON = false;             
       }
  if(readString.indexOf("D2=1")>0) 
      {
       delay(2000); 
       digitalWrite(ledPin9, HIGH);   
       LED4ON = true;
       }else{
       digitalWrite(ledPin9, LOW);    
       LED4ON = false;             
       }
  if(readString.indexOf("F1=1")>0)
      {
       sensorValue = 10;
       outputValue = map(sensorValue, 0, 100, 0, 120);
       analogWrite(analogOutPin, outputValue);
       F1ON = true;
  }else if(readString.indexOf("F2=1")>0)
      {
       sensorValue = 20;
       outputValue = map(sensorValue, 0, 100, 0, 120);
       analogWrite(analogOutPin, outputValue);
       F2ON = true;
  }else if(readString.indexOf("F3=1")>0)
      {
       sensorValue = 30;
       outputValue = map(sensorValue, 0, 100, 0, 120 );
       analogWrite(analogOutPin, outputValue);
       F3ON = true;
  }else if(readString.indexOf("F4=1")>0)
      {
       sensorValue = 40;
       outputValue = map(sensorValue, 0, 100, 0, 120);
       analogWrite(analogOutPin, outputValue);
       F4ON = true;
  }else if(readString.indexOf("F5=1")>0)
      {
       sensorValue = 50;
       outputValue = map(sensorValue, 0, 100, 0, 120);
       analogWrite(analogOutPin, outputValue);
       F5ON = true;
  }else if(readString.indexOf("F6=1")>0)
      {
       sensorValue = 60;
       outputValue = map(sensorValue, 0, 100, 0, 120);
       analogWrite(analogOutPin, outputValue);
       F6ON = true;
  }else if(readString.indexOf("F7=1")>0)
      {
       sensorValue = 70;
       outputValue = map(sensorValue, 0, 100, 0, 120);
       analogWrite(analogOutPin, outputValue);
       F7ON = true;
  }else if(readString.indexOf("F8=1")>0)
      {
       sensorValue = 80;
       outputValue = map(sensorValue, 0, 100, 0, 120);
       analogWrite(analogOutPin, outputValue);
       F8ON = true;
  }else if(readString.indexOf("F9=1")>0)
      {
       sensorValue = 90;
       outputValue = map(sensorValue, 0, 100, 0, 120);
       analogWrite(analogOutPin, outputValue);
       F9ON = true;
  }else if(readString.indexOf("F10=1")>0)
      {
       sensorValue = 100;
       outputValue = map(sensorValue, 0, 100, 0, 120);
       analogWrite(analogOutPin, outputValue);
       F10ON = true;
  }else {
       sensorValue = 0;
       analogWrite(analogOutPin, sensorValue);
       F1ON = false;
       F2ON = false;
       F3ON = false;
       F4ON = false;
       F5ON = false;
       F6ON = false;
       F7ON = false;
       F8ON = false;
       F9ON = false;
       F10ON = false;
      }
}

When you use delay() the microprocessor is NOT DOING ANYTHING except counting milliseconds (OK, it is still processing interrupts)

I’ve written a small explanation on the Arduino playground of how to avoid using delay().

In the menu examples -> digital there is a sketch called blink without delay. This shows you the technique you need to use.

Please don't use text speak (w8) as it annoys the hell out of people here.

Thank you guys i am gone work it.

Hello again i try to use the example 3 from the arduino playground in More complex millis() timers and i create this

void ledstatus(){
      if(LED3ON=false){
   if(readString.indexOf("D1=1")>0)      //pushbuton
      {
       Timer = millis();
       digitalWrite(ledPin8, HIGH);    
       LED3ON = true;
       }}
       if(LED3ON=true){
       if(millis()-Timer >= 2000UL){
       digitalWrite(ledPin8, LOW);    
       LED3ON = false;             
       }}
 if(readString.indexOf("L1=1")>0)                                   //lets check if LED should be lighted
      {
       digitalWrite(ledPin6, HIGH);                                  // set the LED on
       LED1ON = true;
       }else{ 
       digitalWrite(ledPin6, LOW);                                   // set the LED OFF
       LED1ON = false;             
       }
}

but the delay led (ledpin8) never lightson.I cant find what is going rong.

You have only posted part of your code, how can we tell what is wrong if you don't post all the code?
What you have shown only turns off ledPin8 what turns it on?

i first try to make an easy exampe to work and then i put it on my mai code i posted in the beggining.The full example code is this

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

  byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };    //physical mac address
  byte ip[] = { 192, 168, 1, 240 };			  // ip in lan
  byte gateway[] = { 192, 168, 1, 1 };			  // internet access via router
  byte subnet[] = { 255, 255, 255, 0 };                   //subnet mask
  Server server(80);                                      //server port
  int speakerPin = 2; // speaker connected to digital pin 9 

   unsigned long Timer;
   int ledPin6 = 6; 
   int ledPin8 = 8;
   boolean LED1ON = false; 
   boolean LED3ON = false;
   
  String readString = String(30);   //string for fetching data from address

  
void setup(){
  Ethernet.begin(mac, ip, gateway, subnet);
 pinMode(ledPin6, OUTPUT);
 pinMode(ledPin8, OUTPUT);
  Serial.begin(9600);
  pinMode(speakerPin, OUTPUT); // sets the speakerPin to be an output 

}


void loop(){


  


  Client client = server.available();
  if (client) {
    while (client.connected()) {
   if (client.available()) {
    char c = client.read();
     Serial.print(c);
     if (readString.length() < 30) 
      {
        readString.concat(c);        //store characters to string 
      }  
        if (c == '\n') {           //if HTTP request has ended
          
          ledstatus();               //LED Status Sub
          htmlcontent();             //LED Html Content Sub
          
          readString="";          //clearing string for next read
          client.stop();          //stopping client
          delay(100);
         }
       }
     }
   }
 }     


void htmlcontent(){
    Client client = server.available();
    client.println("HTTP/1.1 200 OK");          // now output HTML data starting with standart header
    client.println("Content-Type: text/html");
    client.println();
    client.print("<body>");
client.println("<form method=get name=LED>");
client.println("<INPUT TYPE=CHECKBOX NAME=L1 value=1 >L1
");
 client.println("<INPUT TYPE=CHECKBOX NAME=D1 value=1 >D1
");

    client.println("<INPUT TYPE=SUBMIT VALUE=submit>");
  client.print("Outlet statusL1: "); 
        if (LED1ON)
           client.println("ON"); 
        else
           client.println("OFF");    
       client.print("
 Outlet statusD1: ");
        if (LED3ON)
           client.println("ON"); 
        else
           client.println("OFF");  
    client.println("

");  


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


void ledstatus(){
      if(LED3ON=false){
   if(readString.indexOf("D1=1")>0) 
      {
       Timer = millis();
       digitalWrite(ledPin8, HIGH);    
       LED3ON = true;
       }}
       if(LED3ON=true){
       if(millis()-Timer >= 2000UL){
       digitalWrite(ledPin8, LOW);    
       LED3ON = false;             
       }}
 if(readString.indexOf("L1=1")>0)                                   //lets check if LED should be lighted
      {
       digitalWrite(ledPin6, HIGH);                                  // set the LED on
       LED1ON = true;
       }else{ 
       digitalWrite(ledPin6, LOW);                                   // set the LED OFF
       LED1ON = false;             
       }
}

I would suggest that you print out the value of your string to see if you are getting your required trigger.
Then put a debug print statement after:-
if(readString.indexOf("D1=1")>0)
{
To see if you are catching it.

i take this====
GET /?D1=1 HTTP/1.1
and i dont know what the debug print is

Any chance in doing that last post again? When read in English it is meaningless.

I'll hazard a guess at the meaning of both parties ...

Grumpy_Mike suggest you to put an additional Serial.println() of your readString content at the place where you test for the LED, to check if the string does contain the GET-post of your HTML client. Such a temporary print statement (to be removed in the next code edit) is what we call a "debug print".

It seems to me that toubis wrote he is receiving GET /?D1=1 HTTP/1.1 though it wold be nice to get that confirmed.

Seems the code now is using millis()-timers properly :slight_smile: (or is there still an issue with delay() somewhere?)

(Got myself a ethernet shield recently - havn't yet had time to play with turning a LED ON/OFF via a webclient ... but real soon now)