Anyway to get a specific time?

Hello, so I wanna save a new value to EEPROM only if the button is not pressed for exactly 5s, and doesn't save if more than 5s

Here is my code now:

int interval = 5000;
timer = millis();

if (timer >= interval){
timer = 0;
EEPROM.put(address,setTemp);
digitalWrite(led, HIGH);
delay(500);
}
digitalWrite(led, LOW);

It doesn't work when I change (timer >= interval) to (timer == interval), but works when I try with a led like this

if (timer == 5000){
digitalWrite(led,HIGH);
delay(500);
digitalWrite(led,LOW);
}

Thank you!

if (timer >= interval)

You say this works but the way it is written it will be true once the program has been running for more that 5 seconds. 49 and a bit days later it will be false for 5 seconds then go back to being true. I don't think that the program is doing what you think it is but then you only posted a snippet rather than a full program

if (timer == interval)

Will be true for 1 millisecond each 49 and a bit days

You need to post the complete program

Using >= is the usual way to deal with millis(). Why isn't it acceptable in your case?

Maybe you just need a variable to record the fact that the data has been saved so it does not get saved twice?

Have a look at how millis() is used to manage timing in Several Things at a Time.

And see Using millis() for timing. A beginners guide if you need more explanation.

...R

Immediately after writing to eeprom I would record the current time with

LastTime=Millis()

To test if 5 seconds or more has elapsed, I would use

If ((Millis()-LastTime)>=Interval)

Steve