Reference.Millis History

Hide minor edits - Show changes to markup

November 04, 2009, at 06:08 AM by Paul Badger -
August 15, 2009, at 03:00 PM by David A. Mellis -
Changed lines 1-2 from:

unsigned long millis()

to:

millis()

Changed lines 10-11 from:

The number of milliseconds since the current program started running, as an unsigned long.

to:

Number of milliseconds since the program started (unsigned long)

May 04, 2009, at 02:17 PM by Paul Badger -
Added lines 30-33:

Tip:

Note that the parameter for millis is an unsigned long, errors may be generated if a programmer tries to do math with other datatypes such as ints.

May 04, 2009, at 01:51 PM by Paul Badger -
Changed lines 34-35 from:
to:
  • Tutorial: Blink Without Delay
February 08, 2009, at 01:18 PM by David A. Mellis -
Changed lines 31-33 from:
to:
September 25, 2008, at 11:27 PM by David A. Mellis -
Changed lines 4-5 from:

Returns the number of milliseconds since the Arduino board began running the current program.

to:

Returns the number of milliseconds since the Arduino board began running the current program. This number will overflow (go back to zero), after approximately 50 days.

Changed lines 10-13 from:

The number of milliseconds since the current program started running, as an unsigned long. This number will overflow (go back to zero), after approximately 9 hours and 32 minutes.

Examples

to:

The number of milliseconds since the current program started running, as an unsigned long.

Example

Changed lines 28-79 from:

/* Frequency Test

  • Paul Badger 2007
  • Program to empirically determine the time delay to generate the
  • proper frequency for a an Infrared (IR) Remote Control Receiver module
  • These modules typically require 36 - 52 khz communication frequency
  • depending on specific device.
  • /

int tdelay; unsigned long i, hz; unsigned long time; int outPin = 11;

void setup(){

  pinMode(outPin, OUTPUT);
  Serial.begin(9600);

}

void loop() {

  for (tdelay = 1; tdelay < 12; tdelay++){      // scan across a range of time delays to find the right frequency
    time = millis();               // get start time of inner loop
    for (i = 0; i < 100000; i++){  // time 100,000 cycles through the loop 
      digitalWrite(outPin, HIGH);
      delayMicroseconds(tdelay);
      digitalWrite(outPin, LOW);
      delayMicroseconds(tdelay);
    }
    time = millis() - time;      // compute time through inner loop in milliseconds 
    hz = (1 /((float)time / 100000000.0));   // divide by 100,000 cycles and 1000 milliseconds per second
    // to determine period, then take inverse to convert to hertz
    Serial.print(tdelay, DEC);
    Serial.print("   ");
    Serial.println(hz, DEC);
  }

}@]

Warning:

Note that the parameter for millis is an unsigned long, errors may be generated if a programmer tries to do math with other datatypes such as ints.

Example:
int startTime;             // should be "unsigned long startTime;"

// ...

startTime = millis();     // datatype not large enough to hold data, will generate errors

to:

@]

Changed lines 33-35 from:
to:
September 21, 2008, at 01:35 AM by Paul Badger -
September 21, 2008, at 01:28 AM by Paul Badger -
Changed lines 66-68 from:

Note that the parameter for millis is an unsigned long, errors may be generated if a programmer, tries to do math with other datatypes such as ints.

to:

Note that the parameter for millis is an unsigned long, errors may be generated if a programmer tries to do math with other datatypes such as ints.

September 08, 2008, at 04:29 AM by Paul Badger -
Changed lines 15-16 from:

long time;

to:

unsigned long time;

April 23, 2008, at 06:39 AM by Paul Badger -
Changed lines 10-11 from:

The number of milliseconds since the current program started running, as an unsigned long. This number will overflow (go back to zero), after approximately 9 hours.

to:

The number of milliseconds since the current program started running, as an unsigned long. This number will overflow (go back to zero), after approximately 9 hours and 32 minutes.

December 05, 2007, at 07:42 PM by Paul Badger -
Changed lines 71-72 from:

[@int startTime; // should be "unsigned long startTime;

to:

[@int startTime; // should be "unsigned long startTime;"

December 05, 2007, at 07:41 PM by Paul Badger -
Changed lines 71-72 from:

int startTime; // should be "unsigned long startTime;

to:

[@int startTime; // should be "unsigned long startTime;

Changed lines 75-79 from:

startTime = millis(); // datatype not large enough to hold data, will generate errors

to:

startTime = millis(); // datatype not large enough to hold data, will generate errors@]

December 05, 2007, at 07:41 PM by Paul Badger -
Changed line 65 from:

Note:

to:

Warning:

December 05, 2007, at 07:40 PM by Paul Badger -
Changed lines 65-67 from:

Note: Note that the parameter for millis is an unsigned long, errors may be generated if a programmer, tries to do math with other datatypes such as ints.

to:

Note:

Note that the parameter for millis is an unsigned long, errors may be generated if a programmer, tries to do math with other datatypes such as ints.

Changed lines 71-72 from:

int startTime; // should be "unsigned long startTime;

to:

int startTime; // should be "unsigned long startTime;

Changed lines 75-79 from:

startTime = millis();

to:

startTime = millis(); // datatype not large enough to hold data, will generate errors

December 05, 2007, at 07:38 PM by Paul Badger -
December 05, 2007, at 07:37 PM by Paul Badger -
Added lines 64-78:

Note: Note that the parameter for millis is an unsigned long, errors may be generated if a programmer, tries to do math with other datatypes such as ints.

Example:

int startTime; // should be "unsigned long startTime;

// ...

startTime = millis();

Changed lines 82-83 from:
to:
May 07, 2007, at 01:57 PM by Paul Badger -
Changed line 34 from:
  • depending on specific part number.
to:
  • depending on specific device.
Changed line 58 from:
    // to determine period, then take inverse to convert to hz
to:
    // to determine period, then take inverse to convert to hertz
May 07, 2007, at 01:56 PM by Paul Badger -
Deleted line 68:
April 20, 2007, at 04:48 AM by Paul Badger -
Changed line 57 from:
    hz = (1 /((float)time / 100000000.0));   // divide by 100,000 cycles and 10000 milliseconds per second
to:
    hz = (1 /((float)time / 100000000.0));   // divide by 100,000 cycles and 1000 milliseconds per second
Deleted line 61:
April 20, 2007, at 04:47 AM by Paul Badger -
Changed lines 64-65 from:

} @]

to:

}@]

April 20, 2007, at 04:47 AM by Paul Badger -
Deleted line 28:
Deleted lines 64-65:
Deleted line 65:
April 20, 2007, at 04:46 AM by Paul Badger -
Changed lines 12-13 from:

Example

to:

Examples

Added lines 28-67:

/* Frequency Test

  • Paul Badger 2007
  • Program to empirically determine the time delay to generate the
  • proper frequency for a an Infrared (IR) Remote Control Receiver module
  • These modules typically require 36 - 52 khz communication frequency
  • depending on specific part number.
  • /

int tdelay; unsigned long i, hz; unsigned long time; int outPin = 11;

void setup(){

  pinMode(outPin, OUTPUT);
  Serial.begin(9600);

}

void loop() {

  for (tdelay = 1; tdelay < 12; tdelay++){      // scan across a range of time delays to find the right frequency
    time = millis();               // get start time of inner loop
    for (i = 0; i < 100000; i++){  // time 100,000 cycles through the loop 
      digitalWrite(outPin, HIGH);
      delayMicroseconds(tdelay);
      digitalWrite(outPin, LOW);
      delayMicroseconds(tdelay);
    }
    time = millis() - time;      // compute time through inner loop in milliseconds 
    hz = (1 /((float)time / 100000000.0));   // divide by 100,000 cycles and 10000 milliseconds per second
    // to determine period, then take inverse to convert to hz
    Serial.print(tdelay, DEC);
    Serial.print("   ");
    Serial.println(hz, DEC);

  }

}

October 04, 2006, at 08:41 AM by David A. Mellis -
Changed lines 10-11 from:

The number of milliseconds since the current program started running, as an unsigned long. This number will overflow (go back to zero), after approximately 50 days.

to:

The number of milliseconds since the current program started running, as an unsigned long. This number will overflow (go back to zero), after approximately 9 hours.

March 28, 2006, at 11:17 AM by David A. Mellis - added delay(1000) and changed baud rate to 9600.
Changed line 18 from:
  Serial.begin(19200);
to:
  Serial.begin(9600);
Added lines 25-26:
  // wait a second so as not to send massive amounts of data
  delay(1000);
March 28, 2006, at 02:20 AM by Jeff Gray -
Added line 23:
  //prints time since program started
March 28, 2006, at 02:13 AM by Jeff Gray -
Added lines 12-26:

Example

long time;

void setup(){
  Serial.begin(19200);
}
void loop(){
  Serial.print("Time: ");
  time = millis();
  Serial.println(time);
}

January 13, 2006, at 12:46 AM by 82.186.237.10 -
Changed lines 14-17 from:
to:
December 29, 2005, at 03:05 PM by 82.186.237.10 -
Added lines 1-14:

unsigned long millis()

Description

Returns the number of milliseconds since the Arduino board began running the current program.

Parameters

None

Returns

The number of milliseconds since the current program started running, as an unsigned long. This number will overflow (go back to zero), after approximately 50 days.

See also

Share