[英]How to turn on led but turn off after program has started using arduino uno coding with IDE
[英]Arduino turn the LED on and off but not for equal timelapses without using delay
我正在尝试为Arduino写一个代码,该代码将打开LED 1秒钟,然后将其关闭5秒钟,然后再将其打开1秒钟,依此类推,我需要在不使用delay()的情况下执行此操作功能。
我发现以下代码
if( (currentMils - prevMils_for_2) > interval_for_2 )
{
prevMils_for_2 = currentMils;
if(state_for_2 == LOW)
state_for_2 = HIGH;
else
state_for_2 = LOW;
digitalWrite(2, state_for_2);
}
这使得LED在不使用delay()的情况下闪烁,但是我无法弄清楚如果打开和关闭时间不同,如何应用此技术。
您可以更改interval_for_2值:
if((currentMils - prevMils_for_2) > interval_for_2 ){
prevMils_for_2 = currentMils;
if(state_for_2 == LOW){
state_for_2 = HIGH;
interval_for_2 = 1000;// duration for high
}
else{
state_for_2 = LOW;
interval_for_2 = 2000;// duration for low
}
digitalWrite(2, state_for_2);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.