Cannot create a PWM with 20% duty cycle using micro() timer
You wrote:



if ((state == LOW)&amp;&amp;(current - previous &gt;= TimeOff)){  
    state = HIGH;
    digitalWrite(pin,state);
    previous = current;
  }
else{
  if (current - previous &gt;= TimeOn){
    state = LOW;
    digitalWrite(pin,state);
    previous =current;
  }


While you probably mean:

if (state == LOW &amp;&amp; current - previous &gt;= TimeOff) {  
    state = HIGH;
    digitalWrite(pin, state);
    previous = current;
}
else if (state == HIGH &amp;&amp; current - previous &gt;= TimeOn) {
    state = LOW;
    digitalWrite(pin, state);
    previous =current;
}