IF and timer problem

Properly simple, but I am an amateur…

I have a simple IF statement when that occur a function must start - that’s working

I have added a timer, (not a delay) that secure that the function doesn’t start directly first after the time has passed– that’s working.

Now I need the following:

  • The same IF statement
  • The same time-period
  • If something happened with the parameter in the IF statement in the time- period, that make the IF statement wrong, the timer must be reset and the IF statemen not executed.

Now I need some help.

Post your sketch to see how we can help.

This statement is vague. There are no "parameters" in if statements, only conditional expressions.

Please post your entire sketch and be specific about the conditions you wish to test in your if statement and also the actions you would like to take as a result of those conditions being met.

Sounds like you want "If the condition is true and has been true for a specified time, do something.

    bool condition;
    static unsigned long startTimer = 0;
    if (!condition)
       startTimer = millis();
    else ​if (millis() - startTimer >= requiredTrueTime)
      // 'condition' has been true for requiredTrueTime
      ​// Do something

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.