Some questions about millis()

I know millis() is the number of milliseconds since starting the program, but how can I reset millis() to 0 in order to re-counting the time?

That’s not how it works.

Instead make a new variable timer or startTime and set it to millis(); (when you want to set millis to 0)

Then millis() - startTime gives you the amount of millis you are looking for

1 Like

Hello,

You can’t reset millis().
You can start a time elapsed counter that counts from the time started.

A simple example:

int timeStart;
int timeElapsed;

void setup() 
  {
  timeStart = millis();
  }

void draw() 
  {
  timeElapsed = millis() - timeStart;
  println(timeElapsed);
  }

void keyPressed()
  {
  timeStart = millis();  //Resets time elapsed counter
  }

:)

Other millis() examples here:

1 Like

glv, Thank you so much!! I got it now

1 Like

Chrisir, Thank you for your help!!

1 Like