millis()

I am new on arduino can someone please explain to me how millis() do? how can I use millis() for other software? I was read reference from arduino but I not realy understand

It's not very complicated. The millis() function returns the number of milliseconds that have elapsed since the sketch started running. Since the millis() counter is a 64bit, it overflows and resets to 0 after about 49 days.

It's typically used to measure the elapsed time between events or to control the timing of repetitive events.

so,millis() function will start count from 0 if program execute milis() function.

please explain more...

When your arduino turns on it automatically starts counting milliseconds. If you want to know how many milliseconds it has been since your 'duino turned on then you call millis() and it tells you.

What about this doesn't make sense?

hmmm.... it's look like timer on avr?it's that true? when timer on,tcnt will be start automatic. tcnt count from 0 -255(timer0) and with cycle depend frekuensi he have but function millis() count from 0x0000 0000 to 0xffff ffff,with cycle: 1 milisec. please correct me,if I wrong preseption

You are overcomplicating things.

To use millis you don't need to worry about timers and registers, just follow Fjornir's guidance in his posts above. Millis returns the number of milliseconds since the Arduino board began running the current program.

hmm… :slight_smile:
I just want to know about millis function, I am newbie on arduino…
I saw some program use millis function, during this time i use avrstudio, so I want learn more about arduino
sorry if I overcomplicating things,but i really want to know…
I see posting ‘void functions’ and in side have program like this

example

unsigned long previousMillis;

void setup(){
}

void loop()
{
pause(1000);
}

void pause(long interval) {
previousMillis = millis();
if(millis() - previousMillis < interval) {
}
}

my question, how i can use millis on avrstudio?

are you asking how you can use arduino functions without the arduino runtime environment or IDE?

If you are an experienced avr programmer, you can find all the arduino source code in the download. The code for millis is in a file called wiring.c (its in the directory: hardware/cores/arduino)

If you are not an avr expert, why not use the Arduino IDE ;)

I'm not an avr expert,so i will learn more and more 8-)

thanks Mem,Fjornir,etracer I getting the point now... [smiley=thumbsup.gif]