课程表

Arduino 基础

Arduino 函数库

Arduino 进阶

Arduino 项目

Arduino 传感器

Arduino 电机控制

Arduino 声音

工具箱
速查手册

Arduino - delay()函数

当前位置:免费教程 » 程序设计 » Arduino

delay()函数的工作方式非常简单。 它接受单个整数(或数字)参数。 此数字表示时间(以毫秒为单位)。 程序应该等到下一行代码遇到这个函数。 但是,问题是,delay()函数不是让你的程序等待的好方法,因为它被称为“阻塞"函数。


delay()函数语法

  1. delay (ms) ;

其中, ms 是以毫秒为单位的暂停时间(unsigned long)。


例子

  1. /* Flashing LED
  2. * ------------
  3. * Turns on and off a light emitting diode(LED) connected to a digital
  4. * pin, in intervals of 2 seconds. *
  5. */
  6.  
  7. int ledPin = 13; // LED connected to digital pin 13
  8.  
  9. void setup() {
  10. pinMode(ledPin, OUTPUT); // sets the digital pin as output
  11. }
  12.  
  13. void loop() {
  14. digitalWrite(ledPin, HIGH); // sets the LED on
  15. delay(1000); // waits for a second
  16. digitalWrite(ledPin, LOW); // sets the LED off
  17. delay(1000); // waits for a second
  18. }
转载本站内容时,请务必注明来自W3xue,违者必究。
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号