@lami, while it might well be that
millis() doesn’t change during the ISR, it wouldn’t matter anyhow, since you only need one reading - even if called twice.
It would matter if you tried to compare two readings in one visit to the ISR, then you would use the same value twice if
millis() does not change - although I’m not sure this is actually true for the Core, too.
But I guess there must be something wrong with your code here, because as I see it, the inner
if (timestamp > millis() - TIMEOUT) will never be satisfied with a starting
timestamp = 0.
And even if you start with a higher
timestamp, you will catch the first trigger, but all following bounces too, since
millis() - TIMEOUT will normally always be less then
millis() of the previous visit to
On the other hand if it should be
if (timestamp < millis() - TIMEOUT) this would work only if the bouncing lasts longer than
TIMEOUT, otherwise the last bounce before
TIMEOUT will reset
triggered = 0 and not enter and since there is no bounce following it won’t enter
if (triggered) anymore.
But this version would work if
triggered = 0 happened inside the inner
if. The only drawback of this is, that it ignores all bounces first and does the work after
TIMEOUT, where my version triggeres immediately and ignores the following bounces, at the cost of a bit more code inside