void delay (unsigned long ms)
延时(毫秒)
延时, 单位毫秒(1秒有1000毫秒).
警告:
参数为unsigned long, 因此在延时参数超过32767(int型最大值)时, 需要用"UL"后缀表示为无符号 长整型, 例如: delay(60000UL);. 同样在参数表达式, 切表达式中有int类型时, 需要强制转换为 unsigned long类型, 例如: delay((unsigned long)tdelay * 100UL);.
一下例子设置13引脚对应的LED等以1秒频率闪烁:
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
}