當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Arduino micros()用法及代碼示例

[時間]

說明

返回自 Arduino 板開始運行當前程序以來的微秒數。大約 70 分鍾後,此數字將溢出(回到零)。在 Arduino Portenta 係列的板上,此函數在所有內核上的分辨率為 1 微秒。在 16 MHz Arduino 板(例如 Duemilanove 和 Nano)上,此函數的分辨率為 4 微秒(即返回的值始終是 4 的倍數)。在 8 MHz Arduino 板(例如 LilyPad)上,此函數的分辨率為 8 微秒。

用法

time = micros()

參數

None

返回

返回自 Arduino 板開始運行當前程序以來的微秒數。數據類型:unsigned long

示例代碼

該代碼返回自 Arduino 板開始以來的微秒數。

unsigned long time;

void setup() {
  Serial.begin(9600);
}
void loop() {
  Serial.print("Time: ");
  time = micros();

  Serial.println(time); //prints time since program started
  delay(1000);          // wait a second so as not to send massive amounts of data
}

注意事項和警告

一毫秒有 1,000 微秒,一秒有 1,000,000 微秒。

相關用法


注:本文由純淨天空篩選整理自arduino.cc大神的英文原創作品 micros()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。