Arduino - micros() 函式



micros() 函式返回從 Arduino 開發板開始運行當前程式時起經過的微秒數。此數字會溢位,即在大約 70 分鐘後回到零。在 16MHz Arduino 開發板(例如 Duemilanove 和 Nano)上,此函式的解析度為 4 微秒(即返回的值始終是 4 的倍數)。在 8MHz Arduino 開發板(例如 LilyPad)上,此函式的解析度為 8 微秒。

micros() 函式語法

micros () ;

此函式返回程式啟動以來的微秒數(無符號長整型)

示例

unsigned long time; void setup() { 
   Serial.begin(9600); 
} 

void loop() { 
   Serial.print("Time:");
   time = micros(); //prints time since program started
   Serial.println(time); // wait a second so as not to send massive amounts of data
   delay(1000); 
}
arduino_time.htm
廣告