# millis() function

Hi there,

I am a newbie in arduino.
I would like to ask for this function --> millis()
I saw the code they divided this function with 1000 then they get 1s ?
I thought mili is 10 to the power of -3 ?

Thank you

dividing millis by 1000 will give the number of elapsed seconds. 1000 milliseconds to 1 second

"A millisecond (from milli- and second; abbreviation: ms) is a thousandth (1/1,000) of a second."

10 ^3 is 1000

Exactly so. One millisecond = 1/1000 sec and
1000 msec / (1000 msec/sec) = (1000 / 1000) sec = 1 sec

why 1000ms divide by 1000 ?

10^3 ? I thought milli is 10^-3 ?

Yes, a millisecond is 0.001 Second.
1000 of those and you have 1 second.

An example:

start-time = millis();

time-later = millis();

time_elapsed = time-later - start-time; // number of mS that went by

So why do we divide it by 1000 ?
wont that make it to become even smaller ?

vick5821:
So why do we divide it by 1000 ?
wont that make it to become even smaller ?

1 second is 1000 miliseconds.
1000 (milliseconds) / 1000 = 1 second.

Magic.

Since milliseconds are a small unit of measure, numbers of milliseconds are generally large. Just like you expect something to be 100 pounds much more than 100 tons. So the unit is smaller, the number is bigger. You're diving the number so make the number smaller and the unit bigger.

Do you want to say 1 minute went by, or 60,000mS went by?
Just a matter of convencience for display.
You can do all your math as unsigned long numbers (0x0000 0000 to 0xFFFF FFFF, or 0 to 4,294,967,295,) if you want to, the uC won't care.
4 billion mS is kind of an awkward way of saying 49 days.

What I saw in the coding is milli()/1000 .
so why you put 1000 mill /1000 ?

Like I said - do you want to keep track of seconds? Then divide by 1000 to scale the number down.
(1000 mS) / (1000mS/S) = 1 Second

(3,400mS) / (1000mS/S) = 3.4 Second

I divide by 1000 that having unit of ms/s ?
btw, isnt that 1000 ms = 1s ?

Yes. You are just doing a unit conversion.

1Second/1000mS = 1 so you can multiply (anything * 1) = anything, yes?

1560mS * 1 = 1560mS

Now sub in 1S/1000mS and cancel out common numerator & denominator units:
1560mS * (1Second/1000mS) = 1560 S/1000 = 1.56Seconds

Well, Thank you so much people

Ok..so milli()/1000 will give us the elapsed time in second, like {1,2,3}

if I didnt divide them by 1000ms ? what will I get then ?

f I didnt divide them by 1000ms ? what will I get then ?

Bigger numbers

I will get {1000ms,2000ms,3000ms} ? Instead of the value in simplify form which is {1,2,3}?

No, you could get numbers like 1472, or 4817.

A random number ?

Why ?