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.