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

delay()函数语法

delay (ms) ;

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

例子

/* Flashing LED
   * ------------
   * Turns on and off a light emitting diode(LED) connected to a digital
   * pin, in intervals of 2 seconds. *
*/

int ledPin = 13; // LED connected to digital pin 13

void setup() {
   pinMode(ledPin, OUTPUT); // sets the digital pin as output
}

void loop() {
   digitalWrite(ledPin, HIGH); // sets the LED on
   delay(1000); // waits for a second
   digitalWrite(ledPin, LOW); // sets the LED off
   delay(1000); // waits for a second
}

新闻动态 联系方式 广告合作 招聘英才 安科实验室 帮助与反馈 About Us

Copyright © 2013 - 2019 Ancii.com All Rights Reserved京ICP备18063983号-5 京公网安备11010802014868号