user32156: I am currently working on making some test equipment for µUSB cables. The code is supposed to recoqnise when an error in the cable occurs. Most of it works as expected, but I have some trouble understanding the use of millis() timers. 
I, therefore want to ask, in the code below, how can I make my program pick up on an missing connection in the cable and make sure it turns on the LED always? And secondly, how can I make it stay on for 2 seconds, even if the cable has "fixed" itself again (i.e. the connection has returned)?
Update
It seems that I have misunderstood the assignment. The program should turn on a LED, when an error is present and keeps this on while the error is present (already fixed this in the code). When the connection has been regained a timer should start, which turns off the LED after two seconds. (Here's the trouble I'm having, I can't seem to pinpoint where and how this timer should start)
case microUSB:
  if (Vcc_Ext_val > 50)
  {
    digitalWrite(ActivateLoad, HIGH);
    LoadActivated = true;

  }
  else if (Vcc_Ext_val < 30)
  {
    digitalWrite(ActivateLoad, LOW);
    LoadActivated = false;
  }
  if ((Vcc_Ext_val < 50) || (USB_DP_VAL < 10)|| (USB_DM_VAL < 10))
  {
    PulseCurrentMillis = millis();
    if (FirstPulse == true)
    {
    digitalWrite(RedIntLED, StateLEDON); 
    FirstPulse = false;
    }
    if (PulseCurrentMillis - PulseLastMillis >= PulseInterval)
    {
      PulseLastMillis = PulseCurrentMillis;
      if (LEDState == StateLEDON)
      {
        LEDState = StateLEDOFF;
      }
      else
      {
        LEDState = StateLEDON;
      }
    }
    digitalWrite(GreenIntLED, StateLEDOFF);
    digitalWrite(RedIntLED, LEDState);
  } 
  else
  {
    digitalWrite(GreenIntLED, StateLEDON);
  }
  break;


user32156: I have made it work now.
The working code is as following, if anyone else gets the same issue.
case microUSB:
  if ((Vcc_Ext_val > 50) && (USB_DP_VAL > 10) && (USB_DM_VAL > 10) && (digitalRead(RedIntLED) == StateLEDON))
  {
    if (FirstStart == true)
    {
      StartMillis = millis();
      FirstStart = false;
    }
    PulseCurrentMillis = millis();
    if ((PulseCurrentMillis - StartMillis >= PulseInterval) && (digitalRead(RedIntLED) == StateLEDON))
      {
        PulseLastMillis = PulseCurrentMillis;
        digitalWrite(RedIntLED, StateLEDOFF);
      }
  }
  if (Vcc_Ext_val > 50)
  {
    digitalWrite(ActivateLoad, HIGH);
    LoadActivated = true;

  }
  else if (Vcc_Ext_val < 30)
  {
    digitalWrite(ActivateLoad, LOW);
    LoadActivated = false;
  }
   if ((Vcc_Ext_val < 50) || (USB_DP_VAL < 10) || (USB_DM_VAL < 10))
    { 
      FirstStart = true;
      digitalWrite(GreenIntLED, StateLEDOFF);
      digitalWrite(RedIntLED, StateLEDON);        
    } 
    else
    {
      digitalWrite(GreenIntLED, StateLEDON);
    }
  break;


32156: <p>I am currently working on making some test equipment for µUSB cables. The code is supposed to recoqnise when an error in the cable occurs. Most of it works as expected, but I have some trouble understanding the use of millis() timers. 
I, therefore want to ask, in the code below, how can I make my program pick up on an missing connection in the cable and make sure it turns on the LED always? And secondly, how can I make it stay on for 2 seconds, even if the cable has "fixed" itself again (i.e. the connection has returned)?</p>

<p><em>Update</em>
It seems that I have misunderstood the assignment. The program should turn on a LED, when an error is present and keeps this on while the error is present (already fixed this in the code). When the connection has been regained a timer should start, which turns off the LED after two seconds. (Here's the trouble I'm having, I can't seem to pinpoint where and how this timer should start)</p>

<pre><code>case microUSB:
  if (Vcc_Ext_val &gt; 50)
  {
    digitalWrite(ActivateLoad, HIGH);
    LoadActivated = true;

  }
  else if (Vcc_Ext_val &lt; 30)
  {
    digitalWrite(ActivateLoad, LOW);
    LoadActivated = false;
  }
  if ((Vcc_Ext_val &lt; 50) || (USB_DP_VAL &lt; 10)|| (USB_DM_VAL &lt; 10))
  {
    PulseCurrentMillis = millis();
    if (FirstPulse == true)
    {
    digitalWrite(RedIntLED, StateLEDON); 
    FirstPulse = false;
    }
    if (PulseCurrentMillis - PulseLastMillis &gt;= PulseInterval)
    {
      PulseLastMillis = PulseCurrentMillis;
      if (LEDState == StateLEDON)
      {
        LEDState = StateLEDOFF;
      }
      else
      {
        LEDState = StateLEDON;
      }
    }
    digitalWrite(GreenIntLED, StateLEDOFF);
    digitalWrite(RedIntLED, LEDState);
  } 
  else
  {
    digitalWrite(GreenIntLED, StateLEDON);
  }
  break;
</code></pre>
 32156: <p>I have made it work now.</p>

<p>The working code is as following, if anyone else gets the same issue.</p>

<pre><code>case microUSB:
  if ((Vcc_Ext_val &gt; 50) &amp;&amp; (USB_DP_VAL &gt; 10) &amp;&amp; (USB_DM_VAL &gt; 10) &amp;&amp; (digitalRead(RedIntLED) == StateLEDON))
  {
    if (FirstStart == true)
    {
      StartMillis = millis();
      FirstStart = false;
    }
    PulseCurrentMillis = millis();
    if ((PulseCurrentMillis - StartMillis &gt;= PulseInterval) &amp;&amp; (digitalRead(RedIntLED) == StateLEDON))
      {
        PulseLastMillis = PulseCurrentMillis;
        digitalWrite(RedIntLED, StateLEDOFF);
      }
  }
  if (Vcc_Ext_val &gt; 50)
  {
    digitalWrite(ActivateLoad, HIGH);
    LoadActivated = true;

  }
  else if (Vcc_Ext_val &lt; 30)
  {
    digitalWrite(ActivateLoad, LOW);
    LoadActivated = false;
  }
   if ((Vcc_Ext_val &lt; 50) || (USB_DP_VAL &lt; 10) || (USB_DM_VAL &lt; 10))
    { 
      FirstStart = true;
      digitalWrite(GreenIntLED, StateLEDOFF);
      digitalWrite(RedIntLED, StateLEDON);        
    } 
    else
    {
      digitalWrite(GreenIntLED, StateLEDON);
    }
  break;
</code></pre>
