我刚开始玩arduino。我对delay(1000)
方法有点好奇。下面是一个非常简单的项目,我只是试图以默认的循环速率打印int i,但是在端口13上有led
int led = 13;
int i =0;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
Serial.begin(9600);
Serial.println("Hello");
}
// the loop routine runs over and over again forever:
void loop() {
i++;
Serial.println(i); // wait for a second
blink(1000);
}
void blink(int duration){
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(duration); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(duration);
}
我将实际的闪烁代码移动到它自己的方法,希望延迟实际上就像它的方法暂停,但它也减慢了我的打印速度。
有没有办法让灯光以一种速率闪烁而不影响循环速度?