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.