774726922017 发表于 2018-1-19 21:44:30

流水灯出现问题

初学arduino,在练习流水灯的时候遇到了问题
const int Nbrleds = 6;
const int ledPins[] = {3,5,6,9,10,11};
const int wait = 35;
const int top = 40;
const int mid = 20;
const int bom = 10;
void setup(){
for (int led = 0;led < Nbrleds;led++)
{pinMode(ledPins,OUTPUT);}
}
void loop(){
for (int led = 0;led<Nbrleds - 1;led++)
{ analogWrite(ledPins,top);
delay(wait);
analogWrite(ledPins,top);
analogWrite(ledPins,mid);
delay(wait);
analogWrite(ledPins,top);
analogWrite(ledPins,mid);
analogWrite(ledPins,bom);
delay(wait);
digitalWrite(ledPins,LOW);
delay(wait*3);
}
for (int led = Nbrleds - 1;led > 0;led--)
{ analogWrite(ledPins,top);
delay(wait);
analogWrite(ledPins,top);
analogWrite(ledPins,mid);
delay(wait);
analogWrite(ledPins,top);
analogWrite(ledPins,mid);
analogWrite(ledPins,bom);
delay(wait);
digitalWrite(ledPins,LOW);
delay(wait*3);
}
}


想用pmw实现拖尾效果,期初程序运行没有问题,灯可以正常流动,大概10次之后10、9灯就不亮了。又过了几次循环,11、5、3灯变成了常亮。不知道哪里出现的问题,请各位大神指点,谢谢
页: [1]
查看完整版本: 流水灯出现问题