Millis() refuses to count (Arduino NANO)

Hey guys,

I couldn't make a proper delay function and stripped down my code to:

int timer0 = millis();

void setup() {
Serial.begin(9600);
}

void loop(){
Serial.println(timer0);
}

With this code my Serial monitor only returns 0's.
Some details:

  • Arduino Nano
  • Monitor baudrate is selected at 9600
  • I've tried other data types for timer0 (like byte, long, unsigned long etc.)
  • I've tried setting: int time = millis() and printing this gave the same result

Is millis broken or am I mistaken?

Is millis broken or am I mistaken?

No and yes. The value in timer0 is assigned once, when the Arduino starts up. It is never updated. So, continually printing 0 is what I would expect. Since you expected something different, you are wrong.

Two other things. One, millis() returns a time, NOT a timer. Second, millis() returns an integral value, but that value is NOT an int. RTFM.

Thanks a lot man! Got it working now :))