delayMicroseconds()

描述

將程式暫停一段由參數指定的時間 (單位是微秒),1000 微秒 = 1 毫秒,1000000 微秒 = 1 秒。

目前產生的精確延遲時間最長約為 4000000 微秒,這個值會因為未來 86Duino 釋出的版本不同而改變。延遲如果會超過數秒鐘的話,建議使用 delay() 比較適合。

語法


delayMicroseconds(us)

參數

us: 暫停多少微秒 (unsigned long)

回傳

無回傳值

範例

int outPin = 8;                 // 數位pin 8

void setup()
{
  pinMode(outPin, OUTPUT);      // 將數位 pin 腳設定為輸出
}

void loop()
{
  digitalWrite(outPin, HIGH);   // 點亮 LED 燈
  delayMicroseconds(50);        // 等待 50 微秒     
  digitalWrite(outPin, LOW);    // 熄滅 LED 燈
  delayMicroseconds(50);        // 等待 50 微秒 
}

將 pin 8 設定成輸出,並且連續送出 100 微秒週期的脈衝。

警告與已知問題

一般來說這個函式在一定的時間範圍內運作是很精確的,但是 delayMicroseconds() 等待期間並沒有關閉中斷,我們不能確定它是否一直都能擁有精確且極短的延遲時間。

See also

millis()
micros()
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.