analong delay?

hi there
I have this bit of code below what woks fine, but what I would like it to do is when the stamen is true for a set period of time before executing the code, say for 4s?

int FalSafeValue = analogRead(FalSafeInput);
if (FalSafeValue < 100) {

any help with be appreciated
thanks Joe

Set a flag and watch for when millis() goes past 4000ms. Then run your command.

Something like this (untested) may put you in the right direction.

bool failFlag = false;
unsigned long failStartTime;

loop() {
if ((FalSafeValue < 100) && (failFlag == false)) {  // need failFlag to be false, otherwise, failStarTime keeps updating
   failFlag = true;  // enable the command
  failStartTime = millis();   // start the clock

if ((millis() - failStartTime) > 4000) && (failFlag == true)) {  // see if 4s has gone by yet
   failFlag = false;  //disable the command
   FalSAFE();  // your function

You could add additional flags and logic to keep running that command for a set period of time as well.