Execute "If statement" only one time

if ( sensorAnalogread <999) 
{   
long now = millis ();
    Serial.print(millis());
    Serial.print(" ");
    lcd.setCursor(0,1);
    lcd.print(now); 
    lcd.print(":T"); 
}

As per above code I use infrared sensor on LCD display with timer, and timer will start when sensor value < 999.
But the query is that the "timer stops if the sensor value is greater than 999", I want the timer should not stop after once starting. And after once starting doesn't want to execute the above statement.

Post ALL your code.
Post your code in code tags (this button in the editor </>).

Please try and provide a clearer explanation of what you are trying to do... the above is confusing.

Hi, @mustkimdhukka
Welcome to the forum.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

bool run_once = 1;
.
.
.
if ( (sensorAnalogread <999) && run_once)
{
    run_once = 0;
    long now = millis ();
    Serial.print(millis());
    Serial.print(" ");
    lcd.setCursor(0,1);
    lcd.print(now); 
    lcd.print(":T"); 
}
2 Likes

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