![](/img/trans.png)
[英]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.