millis()
[Timing]
unsigned long millis();
Description
Returns the number of milliseconds since the Custom Element was powered up.
Parameters
None.
Returns
The number of milliseconds.
Example Code
The code creates a clock with the pin 2, toggling the output every 500 milliseconds (1Hz).
void setup() {
(2, "OUT"); // sets the pin 2 label to "OUT"
pinLabel(2, OUTPUT); // sets the digital pin 2 as output
pinMode}
void loop() {
if (millis() % 500 == 0) { // checks if the number of milliseconds is divisible by 500
(2, !digitalRead(2)); // toggles the output on pin 2
digitalWrite}
}
Notes and Warnings
The return value of the millis()
function is of type
unsigned long
, some logic operations may occur if the
programmer to do arithmetic operations with smaller data types
int
.