The code complies but does not work.
The problem is:
long elapsed = millis(); // global scope
void setup() {
}
void loop() {
}
Won't work in platforms where Rtos/something similar is running in the background.
So, other platforms must be also effected.
The correct code is:
unsigned long elapsed = 0; //note: the timestamp must be unsigned to avoid the rollover bug after ~49 days.
void setup() {
elapsed = millis();
}
void loop() {
// use elapsed
}