Delaying an action inside a function My current function is supposed to play a sound effect, then after the sound effect is done (14 seconds), perform the next action (digitalWrite(CONTROLLINO_R1, LOW)).

if (digitalRead(CONTROLLINO_A8) == HIGH &amp;&amp; !skeleLatch) {
  skeleLatch = 1;
  wTrig.trackPlayPoly(2);
  unsigned long currentMillis = millis();
  if((currentMillis-previousMillis) &gt;= 14000) {
    digitalWrite(CONTROLLINO_R1, LOW);
    previousMillis = millis();
  }
}


As it is, it performs both at the same time. I do not know how to correctly implement the delay so that it waits.

Any help would be appreciated. Thank you.
unsigned long triggerMillis = 0;

  if (digitalRead(CONTROLLINO_A8) == HIGH &amp;&amp; !skeleLatch)
  {
    skeleLatch = 1;
    wTrig.trackPlayPoly(2);
    triggerMillis = millis();
  }

  if (millis() - triggerMillis &gt;=14000 &amp;&amp; skeleLatch)
  {
    digitalWrite(CONTROLLINO_R1, LOW);
    skeleLatch = 0;
  }


This should work, depending on how long your CONTROLLINO_A8 is staying high you might want to invest some more time to set up an interrupt on that pin, to make sure you don't miss a trigger.