millis()
描述
回传从 86Duino 开始运行程式到目前所经过的时间,单位是毫秒;这个时间大约会在五十天后溢位 (回到零)。
参数
无参数
回传
程式开始执行至目前所经过的时间,以微秒为单位 (unsigned long)
范例
unsigned long time; void setup(){ Serial.begin(9600); } void loop(){ Serial.print("Time: "); time = millis(); // 印出程式执行的时间 Serial.println(time); // 等待一秒让资料不致输出过多 delay(1000); }
提醒:
millis() 回传值是 unsigned long 资料型别,如果程式设计师尝试以其他的资料型别做运算处理则可能会产生错误。
See also
- micros()
- delay()
- delayMicroseconds()
- Tutorial: Blink Without Delay
本页由热血青年 LBU 译自英文版。
The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.