title: Arduino turn on a led for 2 seconds and then turn off and wait 3 seconds and start all over again
body: <p>I'm using a microcontroler PIC 32 in a diligent  cerebot Mx4cK.
  I have switch implemented on my protoboard and I want to turn on a led after the switch it's activated, then this led have to be in this state for 2 seconds and then have to be off for another 3 seconds and start all over again (on-&gt;2 seconds off-&gt;3 seconds)</p>
  <p>This is my code so far, I think it's missing one condition but I can't find it... can you help me?</p>
  <pre><code>const int led=PIN_LED1;
  const int pinSwitch1=16;
  
  void setup()
  {
    pinMode(pinSwitch1,INPUT);
    pinMode(led,OUTPUT);
       digitalWrite(led,LOW);
  }
  void loop()
  {
     unsigned long actual_time=millis();
     static unsigned long cicle_time=0;
     static unsigned long off_time=0;
   
     static int switch_state1=0;
  
    switch_state1=digitalRead(pinSwitch1);
  
    if (switch_state1==HIGH)
    {
         if((actual_time-cicle_time)&lt;5000)
       {
         digitalWrite(led,HIGH);
         cicle_time=actual_time; 
       }
         if((actual_time-off_time)&gt;2000)
        {
         digitalWrite(led,LOW); 
        off_time=actual_time;
        }
                    
  }
  else 
  {
    digitalWrite(led,LOW); 
  }        
  
  }
  </code></pre>
  <p>Actually my code, blincks for 2 seconds and it's not consider the 3 seconds that it has to be off.</p>
  <p>[This is my new code, I missing an initial condition to light for the first time]</p>
  <p>const int led=PIN_LED1;
  const int pinSwitch1=16;</p>
  <pre><code>void setup()
  {
    pinMode(pinSwitch1,INPUT);
    pinMode(led,OUTPUT);
       digitalWrite(led,LOW);
  }
  void loop()
  {
     unsigned long actual_time=millis();
     static unsigned long cicle_time=0;
     static unsigned long off_time=0;
   
     static int switch_state1=0;
     
     static int cicle_on=0;
  
    switch_state1=digitalRead(pinSwitch1);
  
    if (switch_state1==HIGH)
    {
         if((actual_time-cicle_time)&gt;5000)
       {
         digitalWrite(led,HIGH);
         cicle_time=actual_time; 
         cicle_on=HIGH;
       }
    }
   else 
  {
    digitalWrite(led,LOW); 
  }        
  
         if((actual_time-off_time)&gt;2000)
        {
         digitalWrite(led,LOW); 
         off_time=actual_time;
         cicle_on=LOW;
        }
                    
  
  
  }
  </code></pre>